
figure(1)
close
figure(1)
set(gcf, 'Units', 'Inches', 'Position',   [6.5556 3.9722 10.9444 9.2778], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
%subaxis(numrows,numcolumns,n,'Spacing',.03,'Margin',0.02,'Padding',0.01,'PaddingLeft',0.03,'PaddingBottom',.04)
hold on
FigureTitle = 'Temperature-Pressure';



    % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
       plot(MeltingTemp(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','on');
% %     
        aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
        plot(MeltingTemp(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizes{zz}));
% %     
           
            aaas=aaas+1;
        end
        

yline(11.4,'k','Spinel to Plagioclase','LabelHorizontalAlignment','right','FontSize',10);
yline(25.5,'k','Garnet to Spinel','LabelHorizontalAlignment','right','FontSize',10);
yline(2,'k','MORB crust','FontSize',10,'LabelHorizontalAlignment','right');


ylabel('Pressure (kbar)')
xlabel('Temperature in \circC')

axis square
box on
axis([1250 1600 0 maxPressure4Figures])
%grid on

%set(gca, 'Ytick',[.01 .1 1 10 100])
ax = gca;
ax.XAxis.MinorTick = 'on';
increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
if ax.XLim(1) == 1200
    increment = 10;
end
ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);


%ax.XAxis.MinorTickValues = [.01:.01:.1 .2:.2:1 2:1:10 20:10:100];
set(gca,'YDir','Reverse')

ax.YAxis.MinorTick = 'on';
increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
% if strcmp(Ytext,'Na_2O')
%     increment = .5;
% end
increment=1;
ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);



set(gca,'ticklength',1.3*[0.0200    0.0500])

set(gca,'fontsize', 17,'LineWidth',0.7,'FontName','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')

set(gcf,'name',regexprep(FigureTitle,'\_*',''))
%uistack(h2,'bottom')
% uistack(h1,'bottom')

refline(1/1.5,-1200/1.5)
leg2=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:} 'Adiabats' },'autoupdate','off');
set(leg2,'position',[0.6132 0.7102 0.2132 0.1400])


refline(1/1.5,-1250/1.5)
refline(1/1.5,-1300/1.5)
refline(1/1.5,-1350/1.5)
refline(1/1.5,-1400/1.5)
refline(1/1.5,-1450/1.5)
refline(1/1.5,-1500/1.5)
axis([1250 1600 0 maxPressure4Figures])

set(gca,'XAxisLocation', 'top')



yyaxis right
axis([1250 1600 0 maxPressure4Figures*3.08])
set(gca, 'Ytick',[0:10:maxPressure4Figures/10*30.8])
ax.YAxis(2).MinorTick = 'on';
ax.YAxis(2).MinorTickValues = [0:5:maxPressure4Figures/10*30.8];
ax.YAxis(2).Color='k';
ylabelax.YAxis(2).Color='k';
set(gca,'YDir','Reverse')
ylabel('Depth(km)')



%SismicData_input
%  yyaxis('right')
%   ax1 = gca;
%   ax1_pos = ax1.Position; % position of first axes
% ax2 = axes('Position',ax1_pos,...
%     'XAxisLocation','top',...
%     'YAxisLocation','right',...
%     'Color','none');
% hold on
% axis square
%
% % line(x2,y2,'Parent',ax2,'Color','k')
%
% plot(SismicData(:,1),SismicData(:,2),'k.','Parent',ax2)
%  set(ax2,'YDir','Reverse')
% axis([2.5 7 0 150])
%   ax2.XColor = 'r';
% ax2.YColor = 'r';
%
%   set(gca, 'Ytick',[])


%%

figure(2)
close
figure(2)
set(gcf,'Name','Fitness')
set(gcf,'Position',[63 431 1292 344])
hold on

subaxis(1,4,1,'Margin',.04,'Spacing',.07, 'MarginBottom',.05)
axis square
hold on




    % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
       plot(MeltingTemp(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','on');
        aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
        plot(MeltingTemp(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizes{zz}));
            aaas=aaas+1;
        end
        

refline(1/1.5,-1200/1.5)

leg2=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:} 'Adiabats' },'autoupdate','off');
set(leg2,'position',[0.7314 0.1708 0.1916 0.6613])


axis([1000 1750 0 maxPressure4Figures])
refline(1/1.5,-1250/1.5)
refline(1/1.5,-1300/1.5)
refline(1/1.5,-1350/1.5)
refline(1/1.5,-1400/1.5)
refline(1/1.5,-1450/1.5)
refline(1/1.5,-1500/1.5)
refline(1/1.5,-1550/1.5)
refline(1/1.5,-1600/1.5)


set(gca,'fontsize', 15,'LineWidth',.7,'FontName','Times New Roman')



yline(11.4,'k','Plagioclase','LabelHorizontalAlignment','left','FontSize',10);
yline(25.5,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10);
yline(2,'k');
%yline(Gar2SpTransition,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10,'LabelVerticalAlignment','bottom')
axis([1000 1750 0 maxPressure4Figures])
ylabel('Pressure (kbar)');

% axis([0 max(Fcum) 9 30])
% plot([0.02 0.02],[ 0 30],'r-')
%[Xtext,Ytext] = oxideLabel(1,Indicies(i));

xlabel('Melting Temp');
box on
%grid on
%set(gca, 'Xtick',200:100:1600)
ax = gca;
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):50:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);

set(gca,'ticklength',1.5*[0.0200    0.0500])

set(gca,'XColor', 'k')
set(gca,'YColor', 'k')

set(gca,'YDir','Reverse')

yyaxis right
axis([1000 1750 0 maxPressure4Figures*3.08])
set(gca, 'Ytick',[0:10:maxPressure4Figures/10*30.8])
ax.YAxis(2).MinorTick = 'on';
ax.YAxis(2).MinorTickValues = [0:5:maxPressure4Figures/10*30.8];
ax.YAxis(2).Color='k';
ylabelax.YAxis(2).Color='k';
set(gca,'YDir','Reverse')
ylabel('Depth(km)')


subaxis(1,4,2)
axis square
hold on
    % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
    
       plot(100.*PM_error(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize', eval(runningSizesBad{1}));
 
       
       aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
        plot(100.*PM_error(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize', eval(runningSizes{zz}));

        aaas=aaas+1;
        end


ylabel('Pressure (kbar)');
set(gca,'fontsize', 15,'LineWidth',.7,'FontName','Times New Roman')
yline(11.4,'k','Plagioclase','LabelHorizontalAlignment','left','FontSize',10);
yline(25.5,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10);
% yline(2,'k');
% xline(.04,'k');
%yline(Gar2SpTransition,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10,'LabelVerticalAlignment','bottom')
axis([0 max(PM_error).*100 0 maxPressure4Figures])
%ylabel('Pressure (kbar)')

% axis([0 max(Fcum) 9 30])
% plot([0.02 0.02],[ 0 30],'r-')
%[Xtext,Ytext] = oxideLabel(1,Indicies(i));

xlabel('OPALM RMSD (primary melt error)');
box on
%grid on
%set(gca, 'Xtick',200:100:1600)
ax = gca;
xtickformat(ax, 'percentage');
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):50:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);

set(gca,'ticklength',1.5*[0.0200    0.0500])

set(gca,'XColor', 'k')
set(gca,'YColor', 'k')



% set(gca,'fontsize', 12,'LineWidth',1)
% set(gca,'XColor', 'k')
% set(gca,'YColor', 'k')


set(gca,'YDir','Reverse')

yyaxis right
axis([0  max(PM_error).*100 0 maxPressure4Figures*3.08])
set(gca, 'Ytick',[0:10:maxPressure4Figures/10*30.8])
ax.YAxis(2).MinorTick = 'on';
ax.YAxis(2).MinorTickValues = [0:5:maxPressure4Figures/10*30.8];
ax.YAxis(2).Color='k';
ylabelax.YAxis(2).Color='k';
set(gca,'YDir','Reverse')
ylabel('Depth(km)')




subaxis(1,4,3)
axis square
hold on


    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
    
       plot(PM_error(i),100.*MgnumMelt(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize', eval(runningSizesBad{1}));
 
       
       aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
        plot(100.*PM_error(i),100.*MgnumMelt(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize', eval(runningSizes{zz}));

        aaas=aaas+1;
        end
        
        



% xline(MinMgNumPrimary,'k','HandleVisibility','off');
% xline(MaxMgNumPrimary,'k','HandleVisibility','off');


%axis([ .63 .8 0 max(PM_error)])
ylabel('Mg# Primary Melt')
xlabel('OPALM RMSD (primary melt error)');
box on



ax = gca;
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):.5:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):.1:ax.YLim(2);
xtickformat(ax, 'percentage');

set(gca,'ticklength',1.5*[0.0200    0.0500])
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')



set(gca,'fontsize', 15,'LineWidth',.7,'FontName','Times New Roman')



%%
% figure(301)
% close
% figure(301)
% set(gcf,'position',[237 390 1060 565])
% 
% 
% 
% %load('WHDMM_1350_4cm.m')
% subaxis(1,2,1,'Margin',.05,'Spacing',.12)
% axis square
% hold on
% 
% 
% All_TMelt=Table_Nonunique{:,9};
% All_PMelt=Table_Nonunique{:,8};
% All_TP=Table_Nonunique{:,8};
% All_TMelt_std=Table_Nonunique{:,21};
% All_PMelt_std=Table_Nonunique{:,20};
% 
% All_TMelt_HighTP=Table_Nonunique_highMg{:,9};
% All_PMelt_HighTP=Table_Nonunique_highMg{:,8};
% All_TP_HighTP=Table_Nonunique_highMg{:,8};
% All_TMelt_std_HighTP=Table_Nonunique_highMg{:,21};
% All_PMelt_std_HighTP=Table_Nonunique_highMg{:,20};
% 
% All_TP_std_HighTP=Table_Nonunique_highMg{:,22};
% k = find(All_TP_std_HighTP<30); 
% EEK_k= Table_Nonunique_highMg{k,1};
% 
% All_TMelt_LowTP=Table_Nonunique_lowMg{:,9};
% All_PMelt_LowTP=Table_Nonunique_lowMg{:,8};
% All_TP_LowTP=Table_Nonunique_lowMg{:,8};
% All_TMelt_std_LowTP=Table_Nonunique_lowMg{:,21};
% All_PMelt_std_LowTP=Table_Nonunique_lowMg{:,20};
% 
% 
% % errorbar(All_TMelt(highlight_ReverseFC),All_PMelt(highlight_ReverseFC),...
% %     testallstdP(highlight_ReverseFC)./2,testallstdP(highlight_ReverseFC)./2,...
% %     testallstd(highlight_ReverseFC)./2,testallstd(highlight_ReverseFC)./2,...
% %     '^k','MarkerFaceColor',goodBrown,'MarkerSize',12,'Color',goodBrown,'MarkerEdgeColor',goodBrown)
% % 
% % 
% 
% 
% 
% errorbar(All_TMelt_HighTP,All_PMelt_HighTP,...
%     All_PMelt_std_HighTP./2,All_PMelt_std_HighTP./2,...
%     All_TMelt_std_HighTP./2,All_TMelt_std_HighTP./2,...
%     '^k','MarkerFaceColor',goodSalmon,'MarkerSize',12,'Color',goodSalmon,'MarkerEdgeColor',goodSalmon)
% 
% 
% 
% errorbar(All_TMelt_LowTP,All_PMelt_LowTP,...
%     All_PMelt_std_LowTP./2,All_PMelt_std_LowTP./2,...
%     All_TMelt_std_LowTP./2,All_TMelt_std_LowTP./2,...
%     '^k','MarkerFaceColor',airsuperiorityblue,'MarkerSize',12,'Color',airsuperiorityblue,'MarkerEdgeColor',airsuperiorityblue)
% 
% errorbar(All_TMelt_HighTP(k),All_PMelt_HighTP(k),...
%     All_PMelt_std_HighTP(k)./2,All_PMelt_std_HighTP(k)./2,...
%     All_TMelt_std_HighTP(k)./2,All_TMelt_std_HighTP(k)./2,...
%     '^k','MarkerFaceColor',fuschia,'MarkerSize',12,'Color',fuschia,'MarkerEdgeColor',fuschia)
% 
% 
% plot(MeltingTemp(highlight_ReverseFC),Pb(highlight_ReverseFC),'^','MarkerFaceColor',goodBrown,'Color','k','MarkerSize',12);
% 
% 
% plot(MeltingTemp(HighTp_Index2),Pb(HighTp_Index2),'^','MarkerFaceColor',goodSalmon,'Color','k','MarkerSize',12);
% plot(MeltingTemp(HighTp_Index2(k)),Pb(HighTp_Index2(k)),'^','MarkerFaceColor',fuschia,'Color','k','MarkerSize',12);
% %plot(MeltingTemp(EEK_k),Pb(EEK_k),'^','MarkerFaceColor',green,'Color','k','MarkerSize',12);
% 
% 
% plot(MeltingTemp(lowTp_Index2),Pb(lowTp_Index2),'^','MarkerFaceColor',airsuperiorityblue,'Color','k','MarkerSize',12);
% 
%     load('Step1_Brownetal2020_TEST')
%      colors ={'Cold1','Cold2','Cold3','Cold4'};
%     for layerplotnum=4:-1:1
%     plot(eval(sprintf('Ts_%g', layerplotnum)),Pbeek,'-','Color',eval(colors{layerplotnum}),'linewidth',3)
%     %plot(eval(sprintf('T_%g', layerplotnum)),Pbeek,'-','Color','r','linewidth',3)
%     %plot(eval(sprintf('Tb_%g', layerplotnum)),Pbeek,'-','Color','c','linewidth',3)
%     %plot(eval(sprintf('PooledT_%g', layerplotnum)),eval(sprintf('PooledPb_%g', layerplotnum)), 'ro-','MarkerSize',10,'MarkerFaceColor',eval(colors{layerplotnum}),'Color',black);
%     end
% 
%         for layerplotnum=4:-1:1
%    plot(eval(sprintf('PooledT_%g', layerplotnum)),eval(sprintf('PooledPb_%g', layerplotnum)), 'ro-','MarkerSize',10,'MarkerFaceColor',eval(colors{layerplotnum}),'Color',black);
%         end
%     
%       goodLightBrown= [220,200,163]./256;
%          goodBrown= [168,117,87]./256;
%          goodSalmon= [255,135,130]./256;
%          
% 
% % errorbar(All_TMelt(HighTp_Index2),All_PMelt(HighTp_Index2),...
% %     testallstdP(HighTp_Index2)./2,testallstdP(HighTp_Index2)./2,...
% %     testallstd(HighTp_Index2)./2,testallstd(HighTp_Index2)./2,...
% %     '^k','MarkerFaceColor',red,'MarkerSize',10,'Color',red,'MarkerEdgeColor',black)
% % 
% 
% % test=Table_Nonunique_highMg{:,9};
% % teststd=Table_Nonunique_highMg{:,22};
% % teststdP=Table_Nonunique_highMg{:,21};
% % [k,p]=find(teststd<30);
% % % HighTp_Index2
% % % HighTp_Index2(k)
% % % lowTp_Index2
% % 
% % errorbar(MeltingTemp(lowTp_Index2),Pb(lowTp_Index2),0.*testallstd(lowTp_Index2)./2,0.*testallstd(lowTp_Index2)./2,testallstd(lowTp_Index2)./2,testallstd(lowTp_Index2)./2,'^k','MarkerFaceColor',blue,'MarkerSize',10,'Color',blue,'MarkerEdgeColor',black)
% % errorbar(MeltingTemp(HighTp_Index2(k)),Pb(HighTp_Index2(k)),0.*testallstd(HighTp_Index2(k))./2,0.*testallstd(HighTp_Index2(k))./2,testallstd(HighTp_Index2(k))./2,testallstd(HighTp_Index2(k))./2,'^k','MarkerFaceColor',green,'MarkerSize',10,'Color',green,'MarkerEdgeColor',black)
% % 
% % 
% % 
% % plot(MeltingTemp(highlight_ReverseFC),Pb(highlight_ReverseFC),'^','MarkerFaceColor',goodBrown,'Color','k','MarkerSize',12);
% % plot(MeltingTemp(HighTp_Index2),Pb(HighTp_Index2),'^','MarkerFaceColor',red,'Color','k','MarkerSize',12);
% % plot(MeltingTemp(HighTp_Index2(k)),Pb(HighTp_Index2(k)),'^','MarkerFaceColor',green,'Color','k','MarkerSize',12);
% % plot(MeltingTemp(lowTp_Index2),Pb(lowTp_Index2),'^','MarkerFaceColor',blue,'Color','k','MarkerSize',12);
% % 
% % 
% 
% 
% 
% 
% set(gca,'fontsize', 17,'LineWidth',.7,'FontName','Times New Roman')
% 
% 
% 
% 
% yline(11.4,'k','Plagioclase','LabelHorizontalAlignment','left','FontSize',10);
% yline(25.5,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10);
% yline(2,'k');
% %yline(Gar2SpTransition,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10,'LabelVerticalAlignment','bottom')
% axis([1200 1650 0 45])
% 
% refline(1/1.5, -1250/1.5)
% refline(1/1.5,-1300/1.5)
% refline(1/1.5,-1350/1.5)
% refline(1/1.5,-1400/1.5)
% refline(1/1.5,-1450/1.5)
% refline(1/1.5,-1500/1.5)
% refline(1/1.5,-1550/1.5)
% refline(1/1.5,-1600/1.5)
% axis([1200 1650 0 45])
% 
% ylabel('Pressure (kbar)');
% 
% % axis([0 max(Fcum) 9 30])
% % plot([0.02 0.02],[ 0 30],'r-')
% %[Xtext,Ytext] = oxideLabel(1,Indicies(i));
% 
% xlabel('Melting Temperature (\circC)');
% box on
% %grid on
% %set(gca, 'Xtick',200:100:1600)
% ax = gca;
% ax.XAxis.MinorTick = 'on';
% ax.XAxis.MinorTickValues = ax.XLim(1):10:ax.XLim(2);
% ax = gca;
% ax.YAxis.MinorTick = 'on';
% ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);
% 
% set(gca,'ticklength',1.5*[0.0200    0.0500])
% 
% set(gca,'XColor', 'k')
% set(gca,'YColor', 'k')
% 
% set(gca,'YDir','Reverse')
% 
% yyaxis right
% axis([1200 1650 0 45*3.08])
% set(gca, 'Ytick',[0:10:45/10*30.8])
% ax.YAxis(2).MinorTick = 'on';
% ax.YAxis(2).MinorTickValues = [0:5:maxPressure4Figures/10*30.8];
% ax.YAxis(2).Color='k';
% ylabelax.YAxis(2).Color='k';
% set(gca,'YDir','Reverse')
% 
% 
% 
% 
% subaxis(1,2,2)
% hold on
% axis square
% box on
% 
% axis([1200 1650 1200 1650])
% 
% 
% testall=Table_Nonunique{:,10};
% testallstd=Table_Nonunique{:,22};
% 
% test_highTP=Table_Nonunique_highMg{:,10};
% teststd_highTP=Table_Nonunique_highMg{:,22};
% 
% test_lowTP=Table_Nonunique_lowMg{:,10};
% teststd_lowTP=Table_Nonunique_lowMg{:,22};
% 
% errorbar(MantlePotentialTemp,testall,testallstd,'^k','MarkerFaceColor',goodBrown,'MarkerSize',12,'Color',goodBrown,'MarkerEdgeColor',goodBrown)
% errorbar(MantlePotentialTemp(HighTp_Index2),test_highTP,teststd_highTP,'^','MarkerFaceColor',goodSalmon,'MarkerSize',12,'MarkerEdgeColor',goodSalmon,'Color',goodSalmon)
% errorbar(MantlePotentialTemp(HighTp_Index2(k)),test_highTP(k),teststd_highTP(k),'^k','MarkerFaceColor',fuschia,'MarkerSize',12,'Color',fuschia)
% errorbar(MantlePotentialTemp(lowTp_Index2),test_lowTP,teststd_lowTP,'ob','MarkerFaceColor',airsuperiorityblue,'MarkerSize',12,'Color',airsuperiorityblue)
% 
% 
% plot(MantlePotentialTemp,testall,'^k','MarkerFaceColor',goodBrown,'MarkerSize',12,'Color',goodBrown,'MarkerEdgeColor',black)
% plot(MantlePotentialTemp(HighTp_Index2),test_highTP,'^r','MarkerFaceColor',goodSalmon,'MarkerSize',12,'MarkerEdgeColor',black)
% plot(MantlePotentialTemp(HighTp_Index2(k)),test_highTP(k),'^r','MarkerFaceColor',fuschia,'MarkerSize',12,'MarkerEdgeColor',black)
% 
% plot(MantlePotentialTemp(lowTp_Index2),test_lowTP,'ob','MarkerFaceColor',airsuperiorityblue,'MarkerSize',12,'MarkerEdgeColor',black)
% 
% 
% 
% 
% 
% leg=legend('All Solns','All Solns T_P>1450\circC','All Solns Well-fit T_P>1450\circC', 'All Solns T_P<1350\circC',...
%     'All ML','ML T_P>1450\circC','ML Well-fit T_P>1450\circC', 'ML T_P<1350\circC',...
%     'autoupdate','off');
% set(leg,'position',[0.5759 0.6500 0.2146 0.3354])
% 
% xline(1320,'b-')
% xline(1320-50,'b--')
% xline(1320+50,'b--')
% 
% 
% %plot(MantlePotentialTemp(HighTp_Index2),test,'o')
% refline(1,0)
% xlabel('Single best-fit T_P solution')
% ylabel('All T_P solutions with OPALM error < 1.5%')
% set(gca,'ticklength',1.5*[0.0200    0.0500])
% set(gca,'fontsize', 17,'LineWidth',.7,'FontName','Times New Roman')
% 
% ax = gca;
% ax.XAxis.MinorTick = 'on';
% ax.XAxis.MinorTickValues = ax.XLim(1):10:ax.XLim(2);
% 
% 
% ax.YAxis.MinorTick = 'on';
% ax.YAxis.MinorTickValues = ax.YLim(1):10:ax.YLim(2);
% %

%%
figure(3)
close
figure(3)

LegendsOliv = strcat('Olivine-', UniqueLabels(:))';



set(gcf,'Name','Melting Model Comparison')
set(gcf,'Position',[482 8 1191 516])
hold on
subaxis(1,2,1,'Margin',.03,'Spacing',.04,'PaddingBottom',.05)
axis square
hold on


plot(100.*BAI4(:,10),Pbeek,'-','Color','r','linewidth',3)
plot(100.*running_mBAI4(:,10),Pb_melts,'-','Color','b','linewidth',3)
plot(100.*running_mBAI4(:,10),runningPressure,'-','Color','m','linewidth',3)
plot(100.*poolME_ininc(:,10),Pb_Melting_ininc,'*','Color','c','linewidth',3)
plot(100.*XOW_OUT(:,10),Pbeek,'-','Color','k','linewidth',3)



    % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
       plot(100.*MgnumMelt(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','on');
    
        plot(100.*MgnumOl_New(i),Pb(i),'s','MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','off');
    
        aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
           plot(100.*MgnumMelt(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizes{zz}));
    
           
            aaas=aaas+1;
        end
        
        
        
      
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
         
           plot(100.*MgnumOl_New(i),Pb(i),'s','MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizes{zz}),'handlevisibility','on');
     
            aaas=aaas+1;
        end      


% 
% aaas=1;
% for zz = UniqueLabels_Rows'
%     i =find(ismember(CombinedLabel, CombinedLabel(zz)));
%     
%     p=ismember(i,highlight_ReverseFC);
%     i(p==0)=[];
%     
%     aaas=aaas+1;
% end





% text(MgnumMelt(highlight_ReverseFC), Pb(highlight_ReverseFC), grouplabels((highlight_ReverseFC)),'FontWeight','normal','VerticalAlignment','middle','HorizontalAlignment','center','FontName','Times New Roman','FontSize',12);
% text(MgnumOl_New(highlight_ReverseFC), Pb(highlight_ReverseFC), grouplabels((highlight_ReverseFC)),'FontWeight','normal','VerticalAlignment','middle','HorizontalAlignment','center','FontName','Times New Roman','FontSize',12);



%set(l,'Position',[0.0660 0.7786 0.1434 0.1825])
% yline(Gar2SpTransition,'k','Spinel','LabelHorizontalAlignment','left','FontSize',10)
%yline(11.4,'k','Plagioclase','LabelHorizontalAlignment','left','FontSize',10)
% yline(Gar2SpTransition,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10,'LabelVerticalAlignment','bottom')
% yline(Gar2SpTransition,'k','Spinel','LabelHorizontalAlignment','left','FontSize',10)
yline(11.4,'k','Spinel to Plagioclase','LabelHorizontalAlignment','left','FontSize',10);
yline(25.5,'k','Garnet to Spinel','LabelHorizontalAlignment','left','FontSize',10);
yline(2,'k','MORB crust','FontSize',10,'LabelHorizontalAlignment','left');

xline(100.*MinMgNumPrimary,'k','HandleVisibility','off');
xline(100.*MaxMgNumPrimary,'k','HandleVisibility','off');
% yline(Gar2SpTransition,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10,'LabelVerticalAlignment','bottom')
axis([100.*.65 100.*.92 0 maxPressure4Figures])
l=legend({'Model Near-frac Melts','Model Accumulating Pooled Melts','Model Accum average at Pressure','Model Across-Axis Pooled','Model Residual Mantle',...
Unique_BAD_labels_leg{:} UniqueLabels_leg{:} 'Olivine Mg#'},...
    'autoupdate','off','Location','Best','FontSize',10);

%LegendsOliv{:}
ylabel('Pressure (kbar)')

xlabel('Mg#');
box on
%grid on
%set(gca, 'Xtick',200:100:1600)
ax = gca;
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):1:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);

set(gca,'ticklength',1*[0.0200    0.0500])

set(gca,'fontsize', 18,'LineWidth',1,'fontname','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')

set(gca,'YDir','Reverse')

yyaxis right
axis([100.*.65 100.*.92 0 maxPressure4Figures*3.08])
set(gca, 'Ytick',[0:10:maxPressure4Figures/10*30.8])
ax.YAxis(2).MinorTick = 'on';
ax.YAxis(2).MinorTickValues = [0:5:maxPressure4Figures/10*30.8];
ax.YAxis(2).Color='k';
ylabelax.YAxis(2).Color='k';
set(gca,'YDir','Reverse')
ylabel('Depth(km)')




subaxis(1,2,2)
axis square
hold on


plot(100.*BAI4(:,12),Pbeek,'-','Color','r','linewidth',3)
plot(100.*running_mBAI4(:,12),Pb_melts,'-','Color','b','linewidth',3)
plot(100.*running_mBAI4(:,12),runningPressure,'-','Color','m','linewidth',3)
plot(100.*poolME_ininc(:,12),Pb_Melting_ininc,'*','Color','c','linewidth',3)
plot(100.*XOW_OUT(:,12),Pbeek,'-','Color','k','linewidth',3)

    % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
       plot(100.*NaKMelt(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','on');
    
        aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
         plot(100.*NaKMelt(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizes{zz}));
    
           
            aaas=aaas+1;
        end
        
        
        

yline(11.4,'k','Spinel to Plagioclase','LabelHorizontalAlignment','right','FontSize',10);
yline(25.5,'k','Garnet to Spinel','LabelHorizontalAlignment','right','FontSize',10);
yline(2,'k','MORB crust','FontSize',10,'LabelHorizontalAlignment','right');
axis([0 100.*.4 0 maxPressure4Figures])
ylabel('Pressure (kbar)')


xlabel('NaK#');
box on
%grid on
%set(gca, 'Xtick',200:100:1600)
ax = gca;
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):5:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);

set(gca,'ticklength',1*[0.0200    0.0500])

set(gca,'fontsize', 18,'LineWidth',1,'fontname','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')
set(gca,'YDir','Reverse')

yyaxis right
axis([0 100.*.4 0 maxPressure4Figures*3.08])
set(gca, 'Ytick',[0:10:maxPressure4Figures/10*30.8])
ax.YAxis(2).MinorTick = 'on';
ax.YAxis(2).MinorTickValues = [0:5:maxPressure4Figures/10*30.8];
ax.YAxis(2).Color='k';
ylabelax.YAxis(2).Color='k';
set(gca,'YDir','Reverse')
ylabel('Depth(km)')



%%
figure(4)
close
figure(4)

LegendsOliv = strcat('Olivine-', UniqueLabels(:))';


masterratiosY ={'Eu/Eu*' 'La/Sm' };
masterratiosY ={'Eu/Sm' 'La/Sm' };


set(gcf,'Name','Melting Model Comparison TraceRatio')
set(gcf,'Position',[482 8 1191 516])
hold on
n=1;
subaxis(1,2,n,'Margin',.03,'Spacing',.04,'PaddingBottom',.05)
axis square
hold on



    Desired_Y=masterratiosY{n};
    [b,yvalue] = ismember(Desired_Y,RatioLabels);
    
    
% plot(100.*BAI4(:,10),Pbeek,'-','Color','r','linewidth',3)
% plot(100.*running_mBAI4(:,10),Pb_melts,'-','Color','b','linewidth',3)
% plot(100.*running_mBAI4(:,10),runningPressure,'-','Color','m','linewidth',3)
% plot(100.*poolME_ininc(:,10),Pb_Melting_ininc,'*','Color','c','linewidth',3)
% plot(100.*XOW_OUT(:,10),Pbeek,'-','Color','k','linewidth',3)



%     % Original Data that RevPet does not find a Valid Solution
%     aaas=1;
%     for zztemp = 1:size(Unique_BAD_labels_Rows,1)
%         Unique_BAD_label_here = Unique_BAD_labels{zztemp};
%         i =find(ismember(CombinedLabel, Unique_BAD_label_here));
%         p=ismember(i,BAD_ReverseFC);
%         i(p==0)=[];
%         
%         zz = i(1);
%         plot(100.*MgnumMelt(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','on');
%     
%         plot(100.*MgnumOl_New(i),Pb(i),'s','MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','off');
%     
%         aaas=aaas+1;
%     end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
           plot(runningTraceRatios(i,yvalue)./Sources_DataRatios(yvalue), Pb(i),...
               runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizes{zz}));
    
           
            aaas=aaas+1;
        end
        


% 
% aaas=1;
% for zz = UniqueLabels_Rows'
%     i =find(ismember(CombinedLabel, CombinedLabel(zz)));
%     
%     p=ismember(i,highlight_ReverseFC);
%     i(p==0)=[];
%     
%     aaas=aaas+1;
% end





% text(MgnumMelt(highlight_ReverseFC), Pb(highlight_ReverseFC), grouplabels((highlight_ReverseFC)),'FontWeight','normal','VerticalAlignment','middle','HorizontalAlignment','center','FontName','Times New Roman','FontSize',12);
% text(MgnumOl_New(highlight_ReverseFC), Pb(highlight_ReverseFC), grouplabels((highlight_ReverseFC)),'FontWeight','normal','VerticalAlignment','middle','HorizontalAlignment','center','FontName','Times New Roman','FontSize',12);



%set(l,'Position',[0.0660 0.7786 0.1434 0.1825])
% yline(Gar2SpTransition,'k','Spinel','LabelHorizontalAlignment','left','FontSize',10)
%yline(11.4,'k','Plagioclase','LabelHorizontalAlignment','left','FontSize',10)
% yline(Gar2SpTransition,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10,'LabelVerticalAlignment','bottom')
% yline(Gar2SpTransition,'k','Spinel','LabelHorizontalAlignment','left','FontSize',10)
yline(11.4,'k','Spinel to Plagioclase','LabelHorizontalAlignment','left','FontSize',10);
yline(25.5,'k','Garnet to Spinel','LabelHorizontalAlignment','left','FontSize',10);
yline(2,'k','MORB crust','FontSize',10,'LabelHorizontalAlignment','left');



% yline(Gar2SpTransition,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10,'LabelVerticalAlignment','bottom')
%axis([100.*.65 100.*.92 0 maxPressure4Figures])
l=legend({'Model Near-frac Melts','Model Accumulating Pooled Melts','Model Accum average at Pressure','Model Across-Axis Pooled','Model Residual Mantle',...
Unique_BAD_labels_leg{:} UniqueLabels_leg{:} 'Olivine Mg#'},...
    'autoupdate','off','Location','Best','FontSize',10);

%LegendsOliv{:}
ylabel('Pressure (kbar)')
 xlabel(sprintf('%s_{%s}',RatioLabels{yvalue}, Sources_Labels{2}));
    

box on
%grid on
%set(gca, 'Xtick',200:100:1600)
ax = gca;
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):1:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);

set(gca,'ticklength',1*[0.0200    0.0500])

set(gca,'fontsize', 18,'LineWidth',1,'fontname','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')

set(gca,'YDir','Reverse')

% yyaxis right
% axis([100.*.65 100.*.92 0 maxPressure4Figures*3.08])
% set(gca, 'Ytick',[0:10:maxPressure4Figures/10*30.8])
% ax.YAxis(2).MinorTick = 'on';
% ax.YAxis(2).MinorTickValues = [0:5:maxPressure4Figures/10*30.8];
% ax.YAxis(2).Color='k';
% ylabelax.YAxis(2).Color='k';
% set(gca,'YDir','Reverse')
% ylabel('Depth(km)')





masterratiosY ={'TH230_U238_ACTIVITY' 'TH230_U238_ACTIVITY'};
masterratiosY ={'SR87_SR86' 'ND143_ND144'};
subaxis(1,2,2)
axis square
hold on
n=2;

    Desired_Y=masterratiosY{n};
%     [b,yvalue] = ismember(Desired_Y,RatioLabels);
    


    [b,yvalue] = ismember(Desired_Y,targetStrings_Isotopes);
    
    
% plot(100.*BAI4(:,12),Pbeek,'-','Color','r','linewidth',3)
% plot(100.*running_mBAI4(:,12),Pb_melts,'-','Color','b','linewidth',3)
% plot(100.*running_mBAI4(:,12),runningPressure,'-','Color','m','linewidth',3)
% plot(100.*poolME_ininc(:,12),Pb_Melting_ininc,'*','Color','c','linewidth',3)
% plot(100.*XOW_OUT(:,12),Pbeek,'-','Color','k','linewidth',3)
% % 
%     % Original Data that RevPet does not find a Valid Solution
%     aaas=1;
%     for zztemp = 1:size(Unique_BAD_labels_Rows,1)
%         Unique_BAD_label_here = Unique_BAD_labels{zztemp};
%         i =find(ismember(CombinedLabel, Unique_BAD_label_here));
%         p=ismember(i,BAD_ReverseFC);
%         i(p==0)=[];
%         
%         zz = i(1);
%        plot(100.*NaKMelt(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','on');
%     
%         aaas=aaas+1;
%     end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
           plot(runningIsotopes(i,yvalue), Pb(i),...
               runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizes{zz}));
    
           
            aaas=aaas+1;
        end
        
        
        
        

yline(11.4,'k','Spinel to Plagioclase','LabelHorizontalAlignment','right','FontSize',10);
yline(25.5,'k','Garnet to Spinel','LabelHorizontalAlignment','right','FontSize',10);
yline(2,'k','MORB crust','FontSize',10,'LabelHorizontalAlignment','right');
%axis([0 100.*.4 0 maxPressure4Figures])
ylabel('Pressure (kbar)')

 %xlabel(sprintf('%s_{%s}',RatioLabels{yvalue}, Sources_Labels{2}));
      xlabel( regexprep(Desired_Y,'\_*','/'));
      
%xlabel('NaK#');
box on
%grid on
%set(gca, 'Xtick',200:100:1600)
ax = gca;
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):5:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);

set(gca,'ticklength',1*[0.0200    0.0500])

set(gca,'fontsize', 18,'LineWidth',1,'fontname','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')
set(gca,'YDir','Reverse')

% yyaxis right
% axis([0 100.*.4 0 maxPressure4Figures*3.08])
% set(gca, 'Ytick',[0:10:maxPressure4Figures/10*30.8])
% ax.YAxis(2).MinorTick = 'on';
% ax.YAxis(2).MinorTickValues = [0:5:maxPressure4Figures/10*30.8];
% ax.YAxis(2).Color='k';
% ylabelax.YAxis(2).Color='k';
% set(gca,'YDir','Reverse')
% ylabel('Depth(km)')


%%
figure(5)
close
figure(5)

LegendsOliv = strcat('Olivine-', UniqueLabels(:))';


masterratiosY ={'Eu/Eu*' 'La/Sm' };
masterratiosY ={'Eu/Sm' 'La/Sm' };
masterratiosY ={'HF176_HF177' 'ND143_ND144'};

IndiciesFig1_Y_string = {...
    'Na2O_Primary'  'Avg_P_kbar'...
    'Melting_T_C'   'Melting_P_kbar'...
    'OPALM_RMSD'  'OPALM_RMSD'...
    };


[a,IndiciesFig1_Y]=(ismember(IndiciesFig1_Y_string,ResultLabels));
IndiciesY = [IndiciesFig1_Y];
  ytext=  IndiciesFig1_Y_string{1};


  

set(gcf,'Name','Melting Model Comparison TraceRatio')
set(gcf,'Position',[482 8 1191 516])
hold on
n=1;
subaxis(1,2,n,'Margin',.03,'Spacing',.04,'PaddingBottom',.05)
axis square
hold on



    Desired_Y=masterratiosY{n};
    [b,yvalue] = ismember(Desired_Y,targetStrings_Isotopes);
    
    
% plot(100.*BAI4(:,10),Pbeek,'-','Color','r','linewidth',3)
% plot(100.*running_mBAI4(:,10),Pb_melts,'-','Color','b','linewidth',3)
% plot(100.*running_mBAI4(:,10),runningPressure,'-','Color','m','linewidth',3)
% plot(100.*poolME_ininc(:,10),Pb_Melting_ininc,'*','Color','c','linewidth',3)
% plot(100.*XOW_OUT(:,10),Pbeek,'-','Color','k','linewidth',3)



%     % Original Data that RevPet does not find a Valid Solution
%     aaas=1;
%     for zztemp = 1:size(Unique_BAD_labels_Rows,1)
%         Unique_BAD_label_here = Unique_BAD_labels{zztemp};
%         i =find(ismember(CombinedLabel, Unique_BAD_label_here));
%         p=ismember(i,BAD_ReverseFC);
%         i(p==0)=[];
%         
%         zz = i(1);
%         plot(100.*MgnumMelt(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','on');
%     
%         plot(100.*MgnumOl_New(i),Pb(i),'s','MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','off');
%     
%         aaas=aaas+1;
%     end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
           plot(runningIsotopes(i,yvalue), eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
               runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizes{zz}));
    
           
            aaas=aaas+1;
        end
        


% 
% aaas=1;
% for zz = UniqueLabels_Rows'
%     i =find(ismember(CombinedLabel, CombinedLabel(zz)));
%     
%     p=ismember(i,highlight_ReverseFC);
%     i(p==0)=[];
%     
%     aaas=aaas+1;
% end





% text(MgnumMelt(highlight_ReverseFC), Pb(highlight_ReverseFC), grouplabels((highlight_ReverseFC)),'FontWeight','normal','VerticalAlignment','middle','HorizontalAlignment','center','FontName','Times New Roman','FontSize',12);
% text(MgnumOl_New(highlight_ReverseFC), Pb(highlight_ReverseFC), grouplabels((highlight_ReverseFC)),'FontWeight','normal','VerticalAlignment','middle','HorizontalAlignment','center','FontName','Times New Roman','FontSize',12);



%set(l,'Position',[0.0660 0.7786 0.1434 0.1825])
% yline(Gar2SpTransition,'k','Spinel','LabelHorizontalAlignment','left','FontSize',10)
%yline(11.4,'k','Plagioclase','LabelHorizontalAlignment','left','FontSize',10)
% yline(Gar2SpTransition,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10,'LabelVerticalAlignment','bottom')
% yline(Gar2SpTransition,'k','Spinel','LabelHorizontalAlignment','left','FontSize',10)



% yline(Gar2SpTransition,'k','Garnet','LabelHorizontalAlignment','left','FontSize',10,'LabelVerticalAlignment','bottom')
%axis([100.*.65 100.*.92 0 maxPressure4Figures])
l=legend({'Model Near-frac Melts','Model Accumulating Pooled Melts','Model Accum average at Pressure','Model Across-Axis Pooled','Model Residual Mantle',...
Unique_BAD_labels_leg{:} UniqueLabels_leg{:} 'Olivine Mg#'},...
    'autoupdate','off','Location','Best','FontSize',10);

%LegendsOliv{:}
  ylabel(regexprep(ytext,'_',' '))

xlabel( regexprep(Desired_Y,'\_*','/'));
        

box on
%grid on
%set(gca, 'Xtick',200:100:1600)
ax = gca;
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):1:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);

set(gca,'ticklength',1*[0.0200    0.0500])

set(gca,'fontsize', 18,'LineWidth',1,'fontname','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')


% yyaxis right
% axis([100.*.65 100.*.92 0 maxPressure4Figures*3.08])
% set(gca, 'Ytick',[0:10:maxPressure4Figures/10*30.8])
% ax.YAxis(2).MinorTick = 'on';
% ax.YAxis(2).MinorTickValues = [0:5:maxPressure4Figures/10*30.8];
% ax.YAxis(2).Color='k';
% ylabelax.YAxis(2).Color='k';
% set(gca,'YDir','Reverse')
% ylabel('Depth(km)')





masterratiosY ={'TH230_U238_ACTIVITY' 'TH230_U238_ACTIVITY'};
masterratiosY ={'SR87_SR86' 'ND143_ND144'};
subaxis(1,2,2)
axis square
hold on
n=2;

    Desired_Y=masterratiosY{n};
%     [b,yvalue] = ismember(Desired_Y,RatioLabels);
    


    [b,yvalue] = ismember(Desired_Y,targetStrings_Isotopes);
    
    
% plot(100.*BAI4(:,12),Pbeek,'-','Color','r','linewidth',3)
% plot(100.*running_mBAI4(:,12),Pb_melts,'-','Color','b','linewidth',3)
% plot(100.*running_mBAI4(:,12),runningPressure,'-','Color','m','linewidth',3)
% plot(100.*poolME_ininc(:,12),Pb_Melting_ininc,'*','Color','c','linewidth',3)
% plot(100.*XOW_OUT(:,12),Pbeek,'-','Color','k','linewidth',3)
% % 
%     % Original Data that RevPet does not find a Valid Solution
%     aaas=1;
%     for zztemp = 1:size(Unique_BAD_labels_Rows,1)
%         Unique_BAD_label_here = Unique_BAD_labels{zztemp};
%         i =find(ismember(CombinedLabel, Unique_BAD_label_here));
%         p=ismember(i,BAD_ReverseFC);
%         i(p==0)=[];
%         
%         zz = i(1);
%        plot(100.*NaKMelt(i),Pb(i),runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizesBad{1}),'handlevisibility','on');
%     
%         aaas=aaas+1;
%     end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
           plot(runningIsotopes(i,yvalue), eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
               runningMarkers{zz},'MarkerFaceColor',eval(runningColors_FILL{zz}),'Color',eval(runningColors_LINE{zz}),'MarkerSize',eval(runningSizes{zz}));
    
           
            aaas=aaas+1;
        end
        
        
        
            ylabel(regexprep(ytext,'_',' '))

% yline(11.4,'k','Spinel to Plagioclase','LabelHorizontalAlignment','right','FontSize',10);
% yline(25.5,'k','Garnet to Spinel','LabelHorizontalAlignment','right','FontSize',10);
% yline(2,'k','MORB crust','FontSize',10,'LabelHorizontalAlignment','right');
% %axis([0 100.*.4 0 maxPressure4Figures])
% ylabel('Pressure (kbar)')

 %xlabel(sprintf('%s_{%s}',RatioLabels{yvalue}, Sources_Labels{2}));
      xlabel( regexprep(Desired_Y,'\_*','/'));
      
%xlabel('NaK#');
box on
%grid on
%set(gca, 'Xtick',200:100:1600)
ax = gca;
ax.XAxis.MinorTick = 'on';
ax.XAxis.MinorTickValues = ax.XLim(1):5:ax.XLim(2);
ax = gca;
ax.YAxis.MinorTick = 'on';
ax.YAxis.MinorTickValues = ax.YLim(1):1:ax.YLim(2);

set(gca,'ticklength',1*[0.0200    0.0500])

set(gca,'fontsize', 18,'LineWidth',1,'fontname','Times New Roman')
set(gca,'XColor', 'k')
set(gca,'YColor', 'k')

% yyaxis right
% axis([0 100.*.4 0 maxPressure4Figures*3.08])
% set(gca, 'Ytick',[0:10:maxPressure4Figures/10*30.8])
% ax.YAxis(2).MinorTick = 'on';
% ax.YAxis(2).MinorTickValues = [0:5:maxPressure4Figures/10*30.8];
% ax.YAxis(2).Color='k';
% ylabelax.YAxis(2).Color='k';
% set(gca,'YDir','Reverse')
% ylabel('Depth(km)')
%%
figure(20)
close
    figure(20)
    hold on
          FigureTitle = 'P-T Unique Figure';     

ResultLabels = RevPetResultsTable_ResultsOnly.Properties.VariableNames;
% PointNum	Region_Label	Melting_P_kbar	Melting_T_C	apparentT_P	OPALM_RMSD	StabilityField	MgNum_Erupted	MgNum_Primary	MgNum_Olivine	Avg_P_kbar	Stdev_P_kbar...
%     Average_T_C	Stdev_T_C	Average_TP_C	Stdev_TP_C	Avg_MgNum	Stdev_MgNum	Average_percentFC	Stdev_percentFC	FieldPTString	DistanceFromField	FailureReason	...
%     GarSpPlagTransitions	DistanceToNearestBoundary	PressureFC	OPAM_RMSD_Erupted	OPM_RMSD_Erupted	MG_CPX	MG_PLAG	OPA_FC	OP_FC	O_FC	totalFC	...
%     SiO2_Primary	TiO2_Primary	Al2O3_Primary	Cr2O3_Primary	FeO_Primary	MnO_Primary	MgO_Primary	CaO_Primary	Na2O_Primary	K2O_Primary	P2O5_Primary	NiO_Primary	H2O_Prim	total_Prim	...
%     MgNum_Prim	NaKNum_Primary	CaOAl2O3wt_Primary	CaOAl2O3mol_Primary	Na2OFeO_Primary	K2OTiO2_Primary	OneMinusMgNum_Primary ....
%     Qtz_Primary	Plag_Primary	Oliv_Primary	Cpx_Primary	Ox_Primary	Or_Primary	Ap_Primary	He_Primary	Cs_Primary	Rb_Primary	Tl_Primary	K_Primary	Li_Primary	Ba_Primary	Pb_Primary	Sr_Primary	Mn_Primary	Co_Primary	Zn_Primary	Cu_Primary	Ni_Primary	Be_Primary	La_Primary	Ce_Primary	Pr_Primary	Nd_Primary	Sm_Primary	Eu_Primary	Gd_Primary	Tb_Primary	Dy_Primary	Ho_Primary	Y_Primary	Er_Primary	Yb_Primary	Lu_Primary	Sc_Primary	Ga_Primary	Cr_Primary	Th_Primary	U_Primary	Zr_Primary	Hf_Primary	Sn_Primary	Mo_Primary	Ti_Primary	V_Primary	Nb_Primary	Ta_Primary	W_Primary	H2O_Primary	Ra_Primary	ThU_Primary	LuHf_Primary	SmNd_Primary	LuSc_Primary	HfNd_Primary	LaSm_Primary	RbSr_Primary	EuSm_Primary	EuGd_Primary	NdZr_Primary	SmYb_Primary	ZrY_Primary	NbY_Primary	GdYb_Primary	ZrYb_Primary	ZrHf_Primary	NbTa_Primary	BaLa_Primary	BaPb_Primary	UPb_Primary	EuAnom_Primary	KU_Primary

IndiciesFig1_X_string = {...
    'Melting_T_C' 'Average_T_C'...
    'Average_T_C' 'Avg_P_kbar' ...
    'Melting_P_kbar' 'apparentT_P' ...
    };

IndiciesFig1_Y_string = {...
    'Melting_P_kbar'  'Avg_P_kbar'...
    'Melting_T_C'   'Melting_P_kbar'...
    'OPALM_RMSD'  'OPALM_RMSD'...
    };


% axesMajors = [1200 1400 -6 18; 0 65 10^-2 30; ...
%  -6 18 10^-2 30 ; 1200 1350 10^-2 30;...
%  0 18 10^-2 30; 1200 1350 10^-2 30];

% axesMajors = [1200 1400 -6 18; 0 65 10^-2 2; ...
%  -6 18 10^-2 2 ; 1200 1350 10^-2 2];
axesMajors = [1400 1700 0 40; 0 80 0 .05; ...
    0 40 0 .05 ; 1400 1700 0 .05
    0 4 1400 1700 ; 0 4 1400 1700 ];


axesMajors = [1400 1700 0 45; 0 80 0 0.15; ...
    0 45 0 0.15; 1400 1700 0 0.15
    0 4 1400 1700 ; 0 4 1400 1700 ];

[a,IndiciesFig1_X]=(ismember(IndiciesFig1_X_string,ResultLabels));
[a,IndiciesFig1_Y]=(ismember(IndiciesFig1_Y_string,ResultLabels));


IndiciesX = [IndiciesFig1_X];
IndiciesY = [IndiciesFig1_Y];


numcolumns = 2;
numrows = 2;

 for n = 1:numcolumns.*numrows     
        yvalue =  IndiciesY(n);
        xvalue = IndiciesX(n);
        
        ytext=  IndiciesFig1_Y_string{n};
        xtext = IndiciesFig1_X_string{n};
       
 
        
        
    
        set(gcf, 'Units', 'Inches', 'Position',  [4.3750 2.6528 10.8750 9.7361], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
        subaxis(numrows,numcolumns,n,'Spacing',.03,'Margin',0.02,'Padding',0.01,'PaddingLeft',0.03,'PaddingBottom',.04)
        hold on
         axis square
        %axis(axesMajors(n,:))
        
        
        %arg
        % if ismember(n,[1])
        %     yline(11.5,'k','handlevisibility','off');
        %     yline(25.5,'k','handlevisibility','off');
        % end
        %
        % if ismember(n,[2 3 4])
        %     yline(1.5,'k','handlevisibility','off');
        %     yline(1.5,'k','handlevisibility','off');
        % end
        %
        %
        % if ismember(n,[3 5])
        %     xline(11,'k','handlevisibility','off');
        %     xline(12,'k','handlevisibility','off');
        % end
        
        % if n==1
        % % refline(1/1.5,-1250/1.5)
        % % refline(1/1.5,-1300/1.5)
        % refline(1/1.5,-1350/1.5)
        % refline(1/1.5,-1400/1.5)
        % refline(1/1.5,-1450/1.5)
        % refline(1/1.5,-1500/1.5)
        % refline(1/1.5,-1550/1.5)
        % refline(1/1.5,-1600/1.5)
        % refline(1/1.5,-1650/1.5)
        % refline(1/1.5,-1700/1.5)
        % % refline(1/1.9,-1300/1.9)
        % % refline(1/1.1,-1300/1.1)
        %
        %
        % %refline(1/1.5,-1350/1.5)
        % %axis(axesMajors(n,:))
        % end
        
        
        
        
          % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
        plot(eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',xtext)),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizesBad{1}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'handlevisibility','on');
            
            
        
        aaas=aaas+1;
    end
    
    
    % Original Data with Valid Solutions
    aaas=1;
    for zz = UniqueLabels_Rows'
        i =find(ismember(CombinedLabel, CombinedLabel(zz)));
        p=ismember(i,highlight_ReverseFC);
        i(p==0)=[];
        
      
            plot(eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',xtext)),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}));
   
        
        aaas=aaas+1;
    end
        
        

       
        
        if strcmp(xtext,'FCEXTENT')==1
            %set(gca,'xscale','log')
            %set(gca, 'Xtick',[.01 .1 1 10])
            %axis([0 70 10^-2 10^2 ])
            set(gca, 'Xtick',[0:10:65])
        end
        
        if strcmp(ytext,'BEST FIT')==1
            % set(gca,'yscale','log')
            % set(gca, 'Ytick',[.01 .1 1 10 30])
        end
        
        if strcmp(ytext,'Melting_P_kbar')==1
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end
        if strcmp(ytext,'Avg_P_kbar')==1
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end

        xlabel(regexprep(ResultLabels(xvalue),'_',' '))
        ylabel(regexprep(ResultLabels(yvalue),'_',' '))
        
        
        
        box on
        %grid on

   
        
        set(gca,'ticklength',1.3*[0.0200    0.0500])
        set(gca,'fontsize', 15,'LineWidth',1,'fontname','Times New Roman', 'LineWidth',.7)
        set(gca,'XColor', 'k')
        set(gca,'YColor', 'k')
        %set(gcf,'position',[2.7917 3.4306 9.7361 9.3750])
        % OPTION: uncomment for single (non-subplot plots)
        % legend(TabNames,'location','best')
        % title(FigureTitle)
        % FigureTitle = regexprep(FigureTitle,'\_*','');
        % FigureTitle = regexprep(FigureTitle,'\/','-');

        set(gcf,'name',regexprep(FigureTitle,'\_*',''))
        %uistack(h2,'bottom')
        % uistack(h1,'bottom')
        
          
        %set(gca, 'Ytick',[.01 .1 1 10 100])
        ax = gca;
        ax.XAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        if ax.XLim(1) == 1200
            increment = 10;
        end
        ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);
        
        
        %ax.XAxis.MinorTickValues = [.01:.01:.1 .2:.2:1 2:1:10 20:10:100];
        
        
         ax.YAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
        ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);
        
        
           
        
end


leg2=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}});
set(leg2,'position',[0.2427 0.8623 0.1954 0.0963])


subaxis(2,2,3)
refline(1,0)

subaxis(2,2,4)
refline(1,0)

%%
figure(21)
close
figure(21)
hold on

ResultLabels = RevPetResultsTable_ResultsOnly.Properties.VariableNames;
% PointNum	Region_Label	Melting_P_kbar	Melting_T_C	apparentT_P	OPALM_RMSD	StabilityField	MgNum_Erupted	MgNum_Primary	MgNum_Olivine	Avg_P_kbar	Stdev_P_kbar...
%     Average_T_C	Stdev_T_C	Average_TP_C	Stdev_TP_C	Avg_MgNum	Stdev_MgNum	Average_percentFC	Stdev_percentFC	FieldPTString	DistanceFromField	FailureReason	...
%     GarSpPlagTransitions	DistanceToNearestBoundary	PressureFC	OPAM_RMSD_Erupted	OPM_RMSD_Erupted	MG_CPX	MG_PLAG	OPA_FC	OP_FC	O_FC	totalFC	...
%     SiO2_Primary	TiO2_Primary	Al2O3_Primary	Cr2O3_Primary	FeO_Primary	MnO_Primary	MgO_Primary	CaO_Primary	Na2O_Primary	K2O_Primary	P2O5_Primary	NiO_Primary	H2O_Prim	total_Prim	...
%     MgNum_Prim	NaKNum_Primary	CaOAl2O3wt_Primary	CaOAl2O3mol_Primary	Na2OFeO_Primary	K2OTiO2_Primary	OneMinusMgNum_Primary ....
%     Qtz_Primary	Plag_Primary	Oliv_Primary	Cpx_Primary	Ox_Primary	Or_Primary	Ap_Primary	He_Primary	Cs_Primary	Rb_Primary	Tl_Primary	K_Primary	Li_Primary	Ba_Primary	Pb_Primary	Sr_Primary	Mn_Primary	Co_Primary	Zn_Primary	Cu_Primary	Ni_Primary	Be_Primary	La_Primary	Ce_Primary	Pr_Primary	Nd_Primary	Sm_Primary	Eu_Primary	Gd_Primary	Tb_Primary	Dy_Primary	Ho_Primary	Y_Primary	Er_Primary	Yb_Primary	Lu_Primary	Sc_Primary	Ga_Primary	Cr_Primary	Th_Primary	U_Primary	Zr_Primary	Hf_Primary	Sn_Primary	Mo_Primary	Ti_Primary	V_Primary	Nb_Primary	Ta_Primary	W_Primary	H2O_Primary	Ra_Primary	ThU_Primary	LuHf_Primary	SmNd_Primary	LuSc_Primary	HfNd_Primary	LaSm_Primary	RbSr_Primary	EuSm_Primary	EuGd_Primary	NdZr_Primary	SmYb_Primary	ZrY_Primary	NbY_Primary	GdYb_Primary	ZrYb_Primary	ZrHf_Primary	NbTa_Primary	BaLa_Primary	BaPb_Primary	UPb_Primary	EuAnom_Primary	KU_Primary

FigureTitle = 'Temp-MgO-FeO';
        
IndiciesFig1_X_string = {...
    'MgO_Primary' 'FeO_Primary' ...
    'MgO_Primary' 'FeO_Primary' ...
    };

IndiciesFig1_Y_string = {...
    'Melting_T_C'   'Melting_T_C'...
    'apparentT_P'   'apparentT_P'...
    };



axesMajors = [1400 1700 0 40; 0 80 0 .05; ...
    0 40 0 .05 ; 1400 1700 0 .05
    0 4 1400 1700 ; 0 4 1400 1700 ];


axesMajors = [1400 1700 0 45; 0 80 0 0.15; ...
    0 45 0 0.15; 1400 1700 0 0.15
    0 4 1400 1700 ; 0 4 1400 1700 ];

[a,IndiciesFig1_X]=(ismember(IndiciesFig1_X_string,ResultLabels));
[a,IndiciesFig1_Y]=(ismember(IndiciesFig1_Y_string,ResultLabels));


IndiciesX = [IndiciesFig1_X];
IndiciesY = [IndiciesFig1_Y];


numcolumns = 2;
numrows = 2;

 for n = 1:numcolumns.*numrows     
        yvalue =  IndiciesY(n);
        xvalue = IndiciesX(n);
        
        ytext=  IndiciesFig1_Y_string{n};
        xtext = IndiciesFig1_X_string{n};
       

       
        set(gcf, 'Units', 'Inches', 'Position',  [4.3750 2.6528 10.8750 9.7361], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
        subaxis(numrows,numcolumns,n,'Spacing',.03,'Margin',0.02,'Padding',0.01,'PaddingLeft',0.03,'PaddingBottom',.04)
        hold on
         axis square
        %axis(axesMajors(n,:))

        
        
          % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
        plot(eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',xtext)),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizesBad{1}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'handlevisibility','on');
            
            
        
        aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
          plot(eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',xtext)),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}));
            
            
            aaas=aaas+1;
        end
        
        
        

       
        
        if strcmp(xtext,'FCEXTENT')==1
            %set(gca,'xscale','log')
            %set(gca, 'Xtick',[.01 .1 1 10])
            %axis([0 70 10^-2 10^2 ])
            set(gca, 'Xtick',[0:10:65])
        end
        
        if strcmp(ytext,'BEST FIT')==1
            % set(gca,'yscale','log')
            % set(gca, 'Ytick',[.01 .1 1 10 30])
        end
        
        if strcmp(ytext,'Melting_P_kbar')==1
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end


        xlabel(regexprep(ResultLabels(xvalue),'_',' '))
        ylabel(regexprep(ResultLabels(yvalue),'_',' '))
        
        
        
        box on
        %grid on
        
        %set(gca, 'Ytick',[.01 .1 1 10 100])
        ax = gca;
        ax.XAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        if ax.XLim(1) == 1200
            increment = 10;
        end
        ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);
        
        
        %ax.XAxis.MinorTickValues = [.01:.01:.1 .2:.2:1 2:1:10 20:10:100];
        
        
         ax.YAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
        ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);
        
        
        
   
        
        set(gca,'ticklength',1.3*[0.0200    0.0500])
        set(gca,'fontsize', 15,'LineWidth',1,'fontname','Times New Roman', 'LineWidth',.7)
        set(gca,'XColor', 'k')
        set(gca,'YColor', 'k')
        %set(gcf,'position',[2.7917 3.4306 9.7361 9.3750])
        % OPTION: uncomment for single (non-subplot plots)
        % legend(TabNames,'location','best')
        % title(FigureTitle)
        % FigureTitle = regexprep(FigureTitle,'\_*','');
        % FigureTitle = regexprep(FigureTitle,'\/','-');
        set(gcf,'name',regexprep(FigureTitle,'\_*',''))
        %uistack(h2,'bottom')
        % uistack(h1,'bottom')
        
     
        
end


leg2=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}});
set(leg2,'position',[0.2427 0.8623 0.1954 0.0963])



%%
figure(31)
close
figure(31)
hold on

ResultLabels = RevPetResultsTable_ResultsOnly.Properties.VariableNames;
% PointNum	Region_Label	Melting_P_kbar	Melting_T_C	apparentT_P	OPALM_RMSD	StabilityField	MgNum_Erupted	MgNum_Primary	MgNum_Olivine	Avg_P_kbar	Stdev_P_kbar...
%     Average_T_C	Stdev_T_C	Average_TP_C	Stdev_TP_C	Avg_MgNum	Stdev_MgNum	Average_percentFC	Stdev_percentFC	FieldPTString	DistanceFromField	FailureReason	...
%     GarSpPlagTransitions	DistanceToNearestBoundary	PressureFC	OPAM_RMSD_Erupted	OPM_RMSD_Erupted	MG_CPX	MG_PLAG	OPA_FC	OP_FC	O_FC	totalFC	...
%     SiO2_Primary	TiO2_Primary	Al2O3_Primary	Cr2O3_Primary	FeO_Primary	MnO_Primary	MgO_Primary	CaO_Primary	Na2O_Primary	K2O_Primary	P2O5_Primary	NiO_Primary	H2O_Prim	total_Prim	...
%     MgNum_Prim	NaKNum_Primary	CaOAl2O3wt_Primary	CaOAl2O3mol_Primary	Na2OFeO_Primary	K2OTiO2_Primary	OneMinusMgNum_Primary ....
%     Qtz_Primary	Plag_Primary	Oliv_Primary	Cpx_Primary	Ox_Primary	Or_Primary	Ap_Primary	He_Primary	Cs_Primary	Rb_Primary	Tl_Primary	K_Primary	Li_Primary	Ba_Primary	Pb_Primary	Sr_Primary	Mn_Primary	Co_Primary	Zn_Primary	Cu_Primary	Ni_Primary	Be_Primary	La_Primary	Ce_Primary	Pr_Primary	Nd_Primary	Sm_Primary	Eu_Primary	Gd_Primary	Tb_Primary	Dy_Primary	Ho_Primary	Y_Primary	Er_Primary	Yb_Primary	Lu_Primary	Sc_Primary	Ga_Primary	Cr_Primary	Th_Primary	U_Primary	Zr_Primary	Hf_Primary	Sn_Primary	Mo_Primary	Ti_Primary	V_Primary	Nb_Primary	Ta_Primary	W_Primary	H2O_Primary	Ra_Primary	ThU_Primary	LuHf_Primary	SmNd_Primary	LuSc_Primary	HfNd_Primary	LaSm_Primary	RbSr_Primary	EuSm_Primary	EuGd_Primary	NdZr_Primary	SmYb_Primary	ZrY_Primary	NbY_Primary	GdYb_Primary	ZrYb_Primary	ZrHf_Primary	NbTa_Primary	BaLa_Primary	BaPb_Primary	UPb_Primary	EuAnom_Primary	KU_Primary

FigureTitle = 'Temp-MgO-FeO';
        
IndiciesFig1_X_string = {...
    'Na2O_Primary' 'FeO_Primary' ...
    'Na2O_Primary' 'FeO_Primary' ...
    };

IndiciesFig1_Y_string = {...
    'Melting_P_kbar'   'Melting_P_kbar'...
    'apparentT_P'   'apparentT_P'...
    };



axesMajors = [1400 1700 0 40; 0 80 0 .05; ...
    0 40 0 .05 ; 1400 1700 0 .05
    0 4 1400 1700 ; 0 4 1400 1700 ];


axesMajors = [1400 1700 0 45; 0 80 0 0.15; ...
    0 45 0 0.15; 1400 1700 0 0.15
    0 4 1400 1700 ; 0 4 1400 1700 ];

[a,IndiciesFig1_X]=(ismember(IndiciesFig1_X_string,ResultLabels));
[a,IndiciesFig1_Y]=(ismember(IndiciesFig1_Y_string,ResultLabels));


IndiciesX = [IndiciesFig1_X];
IndiciesY = [IndiciesFig1_Y];


numcolumns = 2;
numrows = 2;

 for n = 1:numcolumns.*numrows     
        yvalue =  IndiciesY(n);
        xvalue = IndiciesX(n);
        
        ytext=  IndiciesFig1_Y_string{n};
        xtext = IndiciesFig1_X_string{n};
       

       
        set(gcf, 'Units', 'Inches', 'Position',  [4.3750 2.6528 10.8750 9.7361], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
        subaxis(numrows,numcolumns,n,'Spacing',.03,'Margin',0.02,'Padding',0.01,'PaddingLeft',0.03,'PaddingBottom',.04)
        hold on
         axis square
        %axis(axesMajors(n,:))

        
        
          % Original Data that RevPet does not find a Valid Solution
%     aaas=1;
%     for zztemp = 1:size(Unique_BAD_labels_Rows,1)
%         Unique_BAD_label_here = Unique_BAD_labels{zztemp};
%         i =find(ismember(CombinedLabel, Unique_BAD_label_here));
%         p=ismember(i,BAD_ReverseFC);
%         i(p==0)=[];
%         
%         zz = i(1);
%         plot(eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',xtext)),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
%                 runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizesBad{1}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'handlevisibility','on');
%             
%             
%         
%         aaas=aaas+1;
%     end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
          plot(eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',xtext)),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}));
            
            
            aaas=aaas+1;
        end
        
        
        

       
        
        if strcmp(xtext,'FCEXTENT')==1
            %set(gca,'xscale','log')
            %set(gca, 'Xtick',[.01 .1 1 10])
            %axis([0 70 10^-2 10^2 ])
            set(gca, 'Xtick',[0:10:65])
        end
        
        if strcmp(ytext,'BEST FIT')==1
            % set(gca,'yscale','log')
            % set(gca, 'Ytick',[.01 .1 1 10 30])
        end
        
        if strcmp(ytext,'Melting_P_kbar')==1
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end


        xlabel(regexprep(ResultLabels(xvalue),'_',' '))
        ylabel(regexprep(ResultLabels(yvalue),'_',' '))
        
        
        
        box on
        %grid on
        
        %set(gca, 'Ytick',[.01 .1 1 10 100])
        ax = gca;
        ax.XAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        if ax.XLim(1) == 1200
            increment = 10;
        end
        ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);
        
        
        %ax.XAxis.MinorTickValues = [.01:.01:.1 .2:.2:1 2:1:10 20:10:100];
        
        
         ax.YAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
        ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);
        
        
        
   
        
        set(gca,'ticklength',1.3*[0.0200    0.0500])
        set(gca,'fontsize', 15,'LineWidth',1,'fontname','Times New Roman', 'LineWidth',.7)
        set(gca,'XColor', 'k')
        set(gca,'YColor', 'k')
        %set(gcf,'position',[2.7917 3.4306 9.7361 9.3750])
        % OPTION: uncomment for single (non-subplot plots)
        % legend(TabNames,'location','best')
        % title(FigureTitle)
        % FigureTitle = regexprep(FigureTitle,'\_*','');
        % FigureTitle = regexprep(FigureTitle,'\/','-');
        set(gcf,'name',regexprep(FigureTitle,'\_*',''))
        %uistack(h2,'bottom')
        % uistack(h1,'bottom')
        
     
        
end


leg2=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}});
set(leg2,'position',[0.2427 0.8623 0.1954 0.0963])



%%

figure(22)
close
figure(22)
hold on
FigureTitle = 'PTfitness';
        
ResultLabels = RevPetResultsTable_ResultsOnly.Properties.VariableNames;
% PointNum	Region_Label	Melting_P_kbar	Melting_T_C	apparentT_P	OPALM_RMSD	StabilityField	MgNum_Erupted	MgNum_Primary	MgNum_Olivine	Avg_P_kbar	Stdev_P_kbar...
%     Average_T_C	Stdev_T_C	Average_TP_C	Stdev_TP_C	Avg_MgNum	Stdev_MgNum	Average_percentFC	Stdev_percentFC	FieldPTString	DistanceFromField	FailureReason	...
%     GarSpPlagTransitions	DistanceToNearestBoundary	PressureFC	OPAM_RMSD_Erupted	OPM_RMSD_Erupted	MG_CPX	MG_PLAG	OPA_FC	OP_FC	O_FC	totalFC	...
%     SiO2_Primary	TiO2_Primary	Al2O3_Primary	Cr2O3_Primary	FeO_Primary	MnO_Primary	MgO_Primary	CaO_Primary	Na2O_Primary	K2O_Primary	P2O5_Primary	NiO_Primary	H2O_Prim	total_Prim	...
%     MgNum_Prim	NaKNum_Primary	CaOAl2O3wt_Primary	CaOAl2O3mol_Primary	Na2OFeO_Primary	K2OTiO2_Primary	OneMinusMgNum_Primary ....
%     Qtz_Primary	Plag_Primary	Oliv_Primary	Cpx_Primary	Ox_Primary	Or_Primary	Ap_Primary	He_Primary	Cs_Primary	Rb_Primary	Tl_Primary	K_Primary	Li_Primary	Ba_Primary	Pb_Primary	Sr_Primary	Mn_Primary	Co_Primary	Zn_Primary	Cu_Primary	Ni_Primary	Be_Primary	La_Primary	Ce_Primary	Pr_Primary	Nd_Primary	Sm_Primary	Eu_Primary	Gd_Primary	Tb_Primary	Dy_Primary	Ho_Primary	Y_Primary	Er_Primary	Yb_Primary	Lu_Primary	Sc_Primary	Ga_Primary	Cr_Primary	Th_Primary	U_Primary	Zr_Primary	Hf_Primary	Sn_Primary	Mo_Primary	Ti_Primary	V_Primary	Nb_Primary	Ta_Primary	W_Primary	H2O_Primary	Ra_Primary	ThU_Primary	LuHf_Primary	SmNd_Primary	LuSc_Primary	HfNd_Primary	LaSm_Primary	RbSr_Primary	EuSm_Primary	EuGd_Primary	NdZr_Primary	SmYb_Primary	ZrY_Primary	NbY_Primary	GdYb_Primary	ZrYb_Primary	ZrHf_Primary	NbTa_Primary	BaLa_Primary	BaPb_Primary	UPb_Primary	EuAnom_Primary	KU_Primary


IndiciesFig1_Y_string = {...
    'Melting_P_kbar' 'Melting_P_kbar'...
    'Melting_P_kbar' 'Melting_P_kbar' ...
    'Melting_P_kbar' 'Melting_P_kbar' ...
    };

IndiciesFig1_X_string = {...
    'SmYb'  'K2O_Primary'...
    'apparentT_P'   'apparentT_P'...
    'OPALM_RMSD'  'OPALM_RMSD'...
    };


% axesMajors = [1200 1400 -6 18; 0 65 10^-2 30; ...
%  -6 18 10^-2 30 ; 1200 1350 10^-2 30;...
%  0 18 10^-2 30; 1200 1350 10^-2 30];

% axesMajors = [1200 1400 -6 18; 0 65 10^-2 2; ...
%  -6 18 10^-2 2 ; 1200 1350 10^-2 2];
axesMajors = [1400 1700 0 40; 0 80 0 .05; ...
    0 40 0 .05 ; 1400 1700 0 .05
    0 4 1400 1700 ; 0 4 1400 1700 ];


axesMajors = [1400 1700 0 45; 0 80 0 0.15; ...
    0 45 0 0.15; 1400 1700 0 0.15
    0 4 1400 1700 ; 0 4 1400 1700 ];

[a,IndiciesFig1_X]=(ismember(IndiciesFig1_X_string,ResultLabels));
[a,IndiciesFig1_Y]=(ismember(IndiciesFig1_Y_string,ResultLabels));




IndiciesX = [IndiciesFig1_X];
IndiciesY = [IndiciesFig1_Y];


numcolumns = 2;
numrows = 2;


 for n = 1:numcolumns.*numrows     
        yvalue =  IndiciesY(n);
        xvalue = IndiciesX(n);
        
        ytext=  IndiciesFig1_Y_string{n};
        xtext = IndiciesFig1_X_string{n};
        

        set(gcf, 'Units', 'Inches', 'Position',  [4.3750 2.6528 10.8750 9.7361], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
        subaxis(numrows,numcolumns,n,'Spacing',.03,'Margin',0.02,'Padding',0.01,'PaddingLeft',0.03,'PaddingBottom',.04)
        hold on
        axis square
        
        %axis(axesMajors(n,:))
        
        
        %arg
        % if ismember(n,[1])
        %     yline(11.5,'k','handlevisibility','off');
        %     yline(25.5,'k','handlevisibility','off');
        % end
        %
        % if ismember(n,[2 3 4])
        %     yline(1.5,'k','handlevisibility','off');
        %     yline(1.5,'k','handlevisibility','off');
        % end
        %
        %
        % if ismember(n,[3 5])
        %     xline(11,'k','handlevisibility','off');
        %     xline(12,'k','handlevisibility','off');
        % end
        
        % if n==1
        % % refline(1/1.5,-1250/1.5)
        % % refline(1/1.5,-1300/1.5)
        % refline(1/1.5,-1350/1.5)
        % refline(1/1.5,-1400/1.5)
        % refline(1/1.5,-1450/1.5)
        % refline(1/1.5,-1500/1.5)
        % refline(1/1.5,-1550/1.5)
        % refline(1/1.5,-1600/1.5)
        % refline(1/1.5,-1650/1.5)
        % refline(1/1.5,-1700/1.5)
        % % refline(1/1.9,-1300/1.9)
        % % refline(1/1.1,-1300/1.1)
        %
        %
        % %refline(1/1.5,-1350/1.5)
        % %axis(axesMajors(n,:))
        % end
        
        
 
    % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
        plot(eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',xtext)),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizesBad{1}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'handlevisibility','on');
            
            
        
        aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
          plot(eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',xtext)),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}));
            
            
            aaas=aaas+1;
        end
        
        
        
        
        if strcmp(xtext,'FCEXTENT')==1
            %set(gca,'xscale','log')
            %set(gca, 'Xtick',[.01 .1 1 10])
            %axis([0 70 10^-2 10^2 ])
            set(gca, 'Xtick',[0:10:65])
        end
        
        if strcmp(ytext,'BEST FIT')==1
            % set(gca,'yscale','log')
            % set(gca, 'Ytick',[.01 .1 1 10 30])
        end
        
        if strcmp(ytext,'Melting_P_kbar')==1
            
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end
        %
        % IndiciesFig1_Y_string = {...
        %      'BEST FIT P'  'NRMSD PM'...
        %      'NRMSD PM'  'NRMSD PM'...
        %     };
        %
        % IndiciesFig1_X_string = {'BEST FIT T' 'FC extent'...
        % 'BEST FIT P' 'BEST FIT Tmp' ...
        % };
        
        % xlabel([xtext])
        % ylabel([ytext])
        
        xlabel(regexprep(ResultLabels(xvalue),'_',' '))
        ylabel(regexprep(ResultLabels(yvalue),'_',' '))
        
        
        
        box on
        %grid on
  
        set(gca,'ticklength',1.3*[0.0200    0.0500])
        set(gca,'fontsize', 15,'LineWidth',1,'fontname','Times New Roman', 'LineWidth',.7)
        set(gca,'XColor', 'k')
        set(gca,'YColor', 'k')
        %set(gcf,'position',[2.7917 3.4306 9.7361 9.3750])
        % OPTION: uncomment for single (non-subplot plots)
        % legend(TabNames,'location','best')
        % title(FigureTitle)
        % FigureTitle = regexprep(FigureTitle,'\_*','');
        % FigureTitle = regexprep(FigureTitle,'\/','-');

        set(gcf,'name',regexprep(FigureTitle,'\_*',''))
        %uistack(h2,'bottom')
        % uistack(h1,'bottom')
        
        
             %set(gca, 'Ytick',[.01 .1 1 10 100])
        ax = gca;
        ax.XAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        if ax.XLim(1) == 1200
            increment = 10;
        end
       % ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);
        numIncre = (ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1))/increment;
 
        ax.XAxis.MinorTickValues = ax.XAxis.TickValues(1)-numIncre.*increment:increment:ax.XAxis.TickValues(end)+numIncre.*increment;
        
         
        
        %ax.XAxis.MinorTickValues = [.01:.01:.1 .2:.2:1 2:1:10 20:10:100];
        ax.YAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
        ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);
        
        
end   



leg2=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}});
set(leg2,'position',[0.2427 0.8623 0.1954 0.0963])





%%

figure(23)
close
figure(23)
hold on
FigureTitle = 'Frac Cryst Info';
        
ResultLabels = RevPetResultsTable_ResultsOnly.Properties.VariableNames;
% PointNum	Region_Label	Melting_P_kbar	Melting_T_C	apparentT_P	OPALM_RMSD	StabilityField	MgNum_Erupted	MgNum_Primary	MgNum_Olivine	Avg_P_kbar	Stdev_P_kbar...
%     Average_T_C	Stdev_T_C	Average_TP_C	Stdev_TP_C	Avg_MgNum	Stdev_MgNum	Average_percentFC	Stdev_percentFC	FieldPTString	DistanceFromField	FailureReason	...
%     GarSpPlagTransitions	DistanceToNearestBoundary	PressureFC	OPAM_RMSD_Erupted	OPM_RMSD_Erupted	MG_CPX	MG_PLAG	OPA_FC	OP_FC	O_FC	totalFC	...
%     SiO2_Primary	TiO2_Primary	Al2O3_Primary	Cr2O3_Primary	FeO_Primary	MnO_Primary	MgO_Primary	CaO_Primary	Na2O_Primary	K2O_Primary	P2O5_Primary	NiO_Primary	H2O_Prim	total_Prim	...
%     MgNum_Prim	NaKNum_Primary	CaOAl2O3wt_Primary	CaOAl2O3mol_Primary	Na2OFeO_Primary	K2OTiO2_Primary	OneMinusMgNum_Primary ....
%     Qtz_Primary	Plag_Primary	Oliv_Primary	Cpx_Primary	Ox_Primary	Or_Primary	Ap_Primary	He_Primary	Cs_Primary	Rb_Primary	Tl_Primary	K_Primary	Li_Primary	Ba_Primary	Pb_Primary	Sr_Primary	Mn_Primary	Co_Primary	Zn_Primary	Cu_Primary	Ni_Primary	Be_Primary	La_Primary	Ce_Primary	Pr_Primary	Nd_Primary	Sm_Primary	Eu_Primary	Gd_Primary	Tb_Primary	Dy_Primary	Ho_Primary	Y_Primary	Er_Primary	Yb_Primary	Lu_Primary	Sc_Primary	Ga_Primary	Cr_Primary	Th_Primary	U_Primary	Zr_Primary	Hf_Primary	Sn_Primary	Mo_Primary	Ti_Primary	V_Primary	Nb_Primary	Ta_Primary	W_Primary	H2O_Primary	Ra_Primary	ThU_Primary	LuHf_Primary	SmNd_Primary	LuSc_Primary	HfNd_Primary	LaSm_Primary	RbSr_Primary	EuSm_Primary	EuGd_Primary	NdZr_Primary	SmYb_Primary	ZrY_Primary	NbY_Primary	GdYb_Primary	ZrYb_Primary	ZrHf_Primary	NbTa_Primary	BaLa_Primary	BaPb_Primary	UPb_Primary	EuAnom_Primary	KU_Primary


IndiciesFig1_Y_string = {...
    'Melting_P_kbar' 'PressureFC'...
    'PressureFC' 'PressureFC' ...
    };

IndiciesFig1_X_string = {...
    'totalFC'  'totalFC'...
    'OPA_FC'   'OP_FC'...
    };


% axesMajors = [1200 1400 -6 18; 0 65 10^-2 30; ...
%  -6 18 10^-2 30 ; 1200 1350 10^-2 30;...
%  0 18 10^-2 30; 1200 1350 10^-2 30];

% axesMajors = [1200 1400 -6 18; 0 65 10^-2 2; ...
%  -6 18 10^-2 2 ; 1200 1350 10^-2 2];
axesMajors = [1400 1700 0 40; 0 80 0 .05; ...
    0 40 0 .05 ; 1400 1700 0 .05
    0 4 1400 1700 ; 0 4 1400 1700 ];


axesMajors = [1400 1700 0 45; 0 80 0 0.15; ...
    0 45 0 0.15; 1400 1700 0 0.15
    0 4 1400 1700 ; 0 4 1400 1700 ];

[a,IndiciesFig1_X]=(ismember(IndiciesFig1_X_string,ResultLabels));
[a,IndiciesFig1_Y]=(ismember(IndiciesFig1_Y_string,ResultLabels));




IndiciesX = [IndiciesFig1_X];
IndiciesY = [IndiciesFig1_Y];


numcolumns = 2;
numrows = 2;


 for n = 1:numcolumns.*numrows     
        yvalue =  IndiciesY(n);
        xvalue = IndiciesX(n);
        
        ytext=  IndiciesFig1_Y_string{n};
        xtext = IndiciesFig1_X_string{n};
        

        set(gcf, 'Units', 'Inches', 'Position',  [4.3750 2.6528 10.8750 9.7361], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
        subaxis(numrows,numcolumns,n,'Spacing',.03,'Margin',0.02,'Padding',0.01,'PaddingLeft',0.03,'PaddingBottom',.04)
        hold on
        axis square
        
        %axis(axesMajors(n,:))
        
        
        %arg
        % if ismember(n,[1])
        %     yline(11.5,'k','handlevisibility','off');
        %     yline(25.5,'k','handlevisibility','off');
        % end
        %
        % if ismember(n,[2 3 4])
        %     yline(1.5,'k','handlevisibility','off');
        %     yline(1.5,'k','handlevisibility','off');
        % end
        %
        %
        % if ismember(n,[3 5])
        %     xline(11,'k','handlevisibility','off');
        %     xline(12,'k','handlevisibility','off');
        % end
        
        % if n==1
        % % refline(1/1.5,-1250/1.5)
        % % refline(1/1.5,-1300/1.5)
        % refline(1/1.5,-1350/1.5)
        % refline(1/1.5,-1400/1.5)
        % refline(1/1.5,-1450/1.5)
        % refline(1/1.5,-1500/1.5)
        % refline(1/1.5,-1550/1.5)
        % refline(1/1.5,-1600/1.5)
        % refline(1/1.5,-1650/1.5)
        % refline(1/1.5,-1700/1.5)
        % % refline(1/1.9,-1300/1.9)
        % % refline(1/1.1,-1300/1.1)
        %
        %
        % %refline(1/1.5,-1350/1.5)
        % %axis(axesMajors(n,:))
        % end
        
        
 
    % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
        plot(eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',xtext)),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizesBad{1}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'handlevisibility','on');
            
            
        
        aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
          plot(eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',xtext)),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}));
            
            
            aaas=aaas+1;
        end
        
        
        
        
        if strcmp(xtext,'FCEXTENT')==1
            %set(gca,'xscale','log')
            %set(gca, 'Xtick',[.01 .1 1 10])
            %axis([0 70 10^-2 10^2 ])
            set(gca, 'Xtick',[0:10:65])
        end
        
        if strcmp(ytext,'BEST FIT')==1
            % set(gca,'yscale','log')
            % set(gca, 'Ytick',[.01 .1 1 10 30])
        end
        
        if strcmp(ytext,'Melting_P_kbar')==1
            
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end
        if strcmp(ytext,'PressureFC')==1
            
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end
        
        %
        % IndiciesFig1_Y_string = {...
        %      'BEST FIT P'  'NRMSD PM'...
        %      'NRMSD PM'  'NRMSD PM'...
        %     };
        %
        % IndiciesFig1_X_string = {'BEST FIT T' 'FC extent'...
        % 'BEST FIT P' 'BEST FIT Tmp' ...
        % };
        
        % xlabel([xtext])
        % ylabel([ytext])
        
        xlabel(regexprep(ResultLabels(xvalue),'_',' '))
        ylabel(regexprep(ResultLabels(yvalue),'_',' '))
        
        
        
        box on
        %grid on
  
        set(gca,'ticklength',1.3*[0.0200    0.0500])
        set(gca,'fontsize', 15,'LineWidth',1,'fontname','Times New Roman', 'LineWidth',.7)
        set(gca,'XColor', 'k')
        set(gca,'YColor', 'k')
        %set(gcf,'position',[2.7917 3.4306 9.7361 9.3750])
        % OPTION: uncomment for single (non-subplot plots)
        % legend(TabNames,'location','best')
        % title(FigureTitle)
        % FigureTitle = regexprep(FigureTitle,'\_*','');
        % FigureTitle = regexprep(FigureTitle,'\/','-');

        set(gcf,'name',regexprep(FigureTitle,'\_*',''))
        %uistack(h2,'bottom')
        % uistack(h1,'bottom')
        
        
             %set(gca, 'Ytick',[.01 .1 1 10 100])
        ax = gca;
        ax.XAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        if ax.XLim(1) == 1200
            increment = 10;
        end
       % ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);
        numIncre = (ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1))/increment;
 
        ax.XAxis.MinorTickValues = ax.XAxis.TickValues(1)-numIncre.*increment:increment:ax.XAxis.TickValues(end)+numIncre.*increment;
        
         
        
        %ax.XAxis.MinorTickValues = [.01:.01:.1 .2:.2:1 2:1:10 20:10:100];
        ax.YAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
        ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);
        
        
end   



leg2=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}});
set(leg2,'position',[0.2427 0.8623 0.1954 0.0963])



%%
%runningDepth(1:size(test,1))=test; 
%%
figure(24)
close
figure(24)
hold on
FigureTitle = 'Axial Depth Info';
        
ResultLabels = RevPetResultsTable_ResultsOnly.Properties.VariableNames;
% PointNum	Region_Label	Melting_P_kbar	Melting_T_C	apparentT_P	OPALM_RMSD	StabilityField	MgNum_Erupted	MgNum_Primary	MgNum_Olivine	Avg_P_kbar	Stdev_P_kbar...
%     Average_T_C	Stdev_T_C	Average_TP_C	Stdev_TP_C	Avg_MgNum	Stdev_MgNum	Average_percentFC	Stdev_percentFC	FieldPTString	DistanceFromField	FailureReason	...
%     GarSpPlagTransitions	DistanceToNearestBoundary	PressureFC	OPAM_RMSD_Erupted	OPM_RMSD_Erupted	MG_CPX	MG_PLAG	OPA_FC	OP_FC	O_FC	totalFC	...
%     SiO2_Primary	TiO2_Primary	Al2O3_Primary	Cr2O3_Primary	FeO_Primary	MnO_Primary	MgO_Primary	CaO_Primary	Na2O_Primary	K2O_Primary	P2O5_Primary	NiO_Primary	H2O_Prim	total_Prim	...
%     MgNum_Prim	NaKNum_Primary	CaOAl2O3wt_Primary	CaOAl2O3mol_Primary	Na2OFeO_Primary	K2OTiO2_Primary	OneMinusMgNum_Primary ....
%     Qtz_Primary	Plag_Primary	Oliv_Primary	Cpx_Primary	Ox_Primary	Or_Primary	Ap_Primary	He_Primary	Cs_Primary	Rb_Primary	Tl_Primary	K_Primary	Li_Primary	Ba_Primary	Pb_Primary	Sr_Primary	Mn_Primary	Co_Primary	Zn_Primary	Cu_Primary	Ni_Primary	Be_Primary	La_Primary	Ce_Primary	Pr_Primary	Nd_Primary	Sm_Primary	Eu_Primary	Gd_Primary	Tb_Primary	Dy_Primary	Ho_Primary	Y_Primary	Er_Primary	Yb_Primary	Lu_Primary	Sc_Primary	Ga_Primary	Cr_Primary	Th_Primary	U_Primary	Zr_Primary	Hf_Primary	Sn_Primary	Mo_Primary	Ti_Primary	V_Primary	Nb_Primary	Ta_Primary	W_Primary	H2O_Primary	Ra_Primary	ThU_Primary	LuHf_Primary	SmNd_Primary	LuSc_Primary	HfNd_Primary	LaSm_Primary	RbSr_Primary	EuSm_Primary	EuGd_Primary	NdZr_Primary	SmYb_Primary	ZrY_Primary	NbY_Primary	GdYb_Primary	ZrYb_Primary	ZrHf_Primary	NbTa_Primary	BaLa_Primary	BaPb_Primary	UPb_Primary	EuAnom_Primary	KU_Primary


IndiciesFig1_Y_string = {...
    'Melting_P_kbar' 'apparentT_P'...
    'FeO_Primary' 'Na2O_Primary' ...
    };




% axesMajors = [1200 1400 -6 18; 0 65 10^-2 30; ...
%  -6 18 10^-2 30 ; 1200 1350 10^-2 30;...
%  0 18 10^-2 30; 1200 1350 10^-2 30];

% axesMajors = [1200 1400 -6 18; 0 65 10^-2 2; ...
%  -6 18 10^-2 2 ; 1200 1350 10^-2 2];
axesMajors = [1400 1700 0 40; 0 80 0 .05; ...
    0 40 0 .05 ; 1400 1700 0 .05
    0 4 1400 1700 ; 0 4 1400 1700 ];


axesMajors = [1400 1700 0 45; 0 80 0 0.15; ...
    0 45 0 0.15; 1400 1700 0 0.15
    0 4 1400 1700 ; 0 4 1400 1700 ];

[a,IndiciesFig1_X]=(ismember(IndiciesFig1_X_string,ResultLabels));
[a,IndiciesFig1_Y]=(ismember(IndiciesFig1_Y_string,ResultLabels));




IndiciesX = [IndiciesFig1_X];
IndiciesY = [IndiciesFig1_Y];


numcolumns = 2;
numrows = 2;


 for n = 1:numcolumns.*numrows     
        yvalue =  IndiciesY(n);
        xvalue = IndiciesX(n);
        
        ytext=  IndiciesFig1_Y_string{n};
        xtext = IndiciesFig1_X_string{n};
        

        set(gcf, 'Units', 'Inches', 'Position',  [4.3750 2.6528 10.8750 9.7361], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
        subaxis(numrows,numcolumns,n,'Spacing',.03,'Margin',0.02,'Padding',0.01,'PaddingLeft',0.03,'PaddingBottom',.04)
        hold on
        axis square
        
        %axis(axesMajors(n,:))
        
        
        %arg
        % if ismember(n,[1])
        %     yline(11.5,'k','handlevisibility','off');
        %     yline(25.5,'k','handlevisibility','off');
        % end
        %
        % if ismember(n,[2 3 4])
        %     yline(1.5,'k','handlevisibility','off');
        %     yline(1.5,'k','handlevisibility','off');
        % end
        %
        %
        % if ismember(n,[3 5])
        %     xline(11,'k','handlevisibility','off');
        %     xline(12,'k','handlevisibility','off');
        % end
        
        % if n==1
        % % refline(1/1.5,-1250/1.5)
        % % refline(1/1.5,-1300/1.5)
        % refline(1/1.5,-1350/1.5)
        % refline(1/1.5,-1400/1.5)
        % refline(1/1.5,-1450/1.5)
        % refline(1/1.5,-1500/1.5)
        % refline(1/1.5,-1550/1.5)
        % refline(1/1.5,-1600/1.5)
        % refline(1/1.5,-1650/1.5)
        % refline(1/1.5,-1700/1.5)
        % % refline(1/1.9,-1300/1.9)
        % % refline(1/1.1,-1300/1.1)
        %
        %
        % %refline(1/1.5,-1350/1.5)
        % %axis(axesMajors(n,:))
        % end
        
        
 
    % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
        plot(runningDepth(i),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizesBad{1}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'handlevisibility','on');
            
            
        
        aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
          plot(runningDepth(i),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}));
            
            
            aaas=aaas+1;
        end
        
        
        
        
        if strcmp(xtext,'FCEXTENT')==1
            %set(gca,'xscale','log')
            %set(gca, 'Xtick',[.01 .1 1 10])
            %axis([0 70 10^-2 10^2 ])
            set(gca, 'Xtick',[0:10:65])
        end
        
        if strcmp(ytext,'BEST FIT')==1
            % set(gca,'yscale','log')
            % set(gca, 'Ytick',[.01 .1 1 10 30])
        end
        
        if strcmp(ytext,'Melting_P_kbar')==1
            
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end
        if strcmp(ytext,'PressureFC')==1
            
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end
        
        %
        % IndiciesFig1_Y_string = {...
        %      'BEST FIT P'  'NRMSD PM'...
        %      'NRMSD PM'  'NRMSD PM'...
        %     };
        %
        % IndiciesFig1_X_string = {'BEST FIT T' 'FC extent'...
        % 'BEST FIT P' 'BEST FIT Tmp' ...
        % };
        
        % xlabel([xtext])
        % ylabel([ytext])
        
        xlabel('Axial Depth (m)')
        ylabel(regexprep(ResultLabels(yvalue),'_',' '))
        
        
        
        box on
        %grid on
  
        set(gca,'ticklength',1.3*[0.0200    0.0500])
        set(gca,'fontsize', 15,'LineWidth',1,'fontname','Times New Roman', 'LineWidth',.7)
        set(gca,'XColor', 'k')
        set(gca,'YColor', 'k')
        %set(gcf,'position',[2.7917 3.4306 9.7361 9.3750])
        % OPTION: uncomment for single (non-subplot plots)
        % legend(TabNames,'location','best')
        % title(FigureTitle)
        % FigureTitle = regexprep(FigureTitle,'\_*','');
        % FigureTitle = regexprep(FigureTitle,'\/','-');

        set(gcf,'name',regexprep(FigureTitle,'\_*',''))
        %uistack(h2,'bottom')
        % uistack(h1,'bottom')
        
        
             %set(gca, 'Ytick',[.01 .1 1 10 100])
        ax = gca;
        ax.XAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        if ax.XLim(1) == 1200
            increment = 10;
        end
       % ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);
       increment=500;
        numIncre = (ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1))/increment;
 
        ax.XAxis.MinorTickValues = ax.XAxis.TickValues(1)-numIncre.*increment:increment:ax.XAxis.TickValues(end)+numIncre.*increment;
        
         
        
        %ax.XAxis.MinorTickValues = [.01:.01:.1 .2:.2:1 2:1:10 20:10:100];
        ax.YAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
        ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);
        
        
end   



leg2=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}});
set(leg2,'position',[0.2427 0.8623 0.1954 0.0963])



%%
%runningSprRate(1:size(test2,1))=test2; 
%%
figure(27)
close
figure(27)
hold on
FigureTitle = 'Spreading Rate Info';
        
ResultLabels = RevPetResultsTable_ResultsOnly.Properties.VariableNames;
% PointNum	Region_Label	Melting_P_kbar	Melting_T_C	apparentT_P	OPALM_RMSD	StabilityField	MgNum_Erupted	MgNum_Primary	MgNum_Olivine	Avg_P_kbar	Stdev_P_kbar...
%     Average_T_C	Stdev_T_C	Average_TP_C	Stdev_TP_C	Avg_MgNum	Stdev_MgNum	Average_percentFC	Stdev_percentFC	FieldPTString	DistanceFromField	FailureReason	...
%     GarSpPlagTransitions	DistanceToNearestBoundary	PressureFC	OPAM_RMSD_Erupted	OPM_RMSD_Erupted	MG_CPX	MG_PLAG	OPA_FC	OP_FC	O_FC	totalFC	...
%     SiO2_Primary	TiO2_Primary	Al2O3_Primary	Cr2O3_Primary	FeO_Primary	MnO_Primary	MgO_Primary	CaO_Primary	Na2O_Primary	K2O_Primary	P2O5_Primary	NiO_Primary	H2O_Prim	total_Prim	...
%     MgNum_Prim	NaKNum_Primary	CaOAl2O3wt_Primary	CaOAl2O3mol_Primary	Na2OFeO_Primary	K2OTiO2_Primary	OneMinusMgNum_Primary ....
%     Qtz_Primary	Plag_Primary	Oliv_Primary	Cpx_Primary	Ox_Primary	Or_Primary	Ap_Primary	He_Primary	Cs_Primary	Rb_Primary	Tl_Primary	K_Primary	Li_Primary	Ba_Primary	Pb_Primary	Sr_Primary	Mn_Primary	Co_Primary	Zn_Primary	Cu_Primary	Ni_Primary	Be_Primary	La_Primary	Ce_Primary	Pr_Primary	Nd_Primary	Sm_Primary	Eu_Primary	Gd_Primary	Tb_Primary	Dy_Primary	Ho_Primary	Y_Primary	Er_Primary	Yb_Primary	Lu_Primary	Sc_Primary	Ga_Primary	Cr_Primary	Th_Primary	U_Primary	Zr_Primary	Hf_Primary	Sn_Primary	Mo_Primary	Ti_Primary	V_Primary	Nb_Primary	Ta_Primary	W_Primary	H2O_Primary	Ra_Primary	ThU_Primary	LuHf_Primary	SmNd_Primary	LuSc_Primary	HfNd_Primary	LaSm_Primary	RbSr_Primary	EuSm_Primary	EuGd_Primary	NdZr_Primary	SmYb_Primary	ZrY_Primary	NbY_Primary	GdYb_Primary	ZrYb_Primary	ZrHf_Primary	NbTa_Primary	BaLa_Primary	BaPb_Primary	UPb_Primary	EuAnom_Primary	KU_Primary


IndiciesFig1_Y_string = {...
    'Melting_P_kbar' 'apparentT_P'...
    'FeO_Primary' 'Na2O_Primary' ...
    };




% axesMajors = [1200 1400 -6 18; 0 65 10^-2 30; ...
%  -6 18 10^-2 30 ; 1200 1350 10^-2 30;...
%  0 18 10^-2 30; 1200 1350 10^-2 30];

% axesMajors = [1200 1400 -6 18; 0 65 10^-2 2; ...
%  -6 18 10^-2 2 ; 1200 1350 10^-2 2];
axesMajors = [1400 1700 0 40; 0 80 0 .05; ...
    0 40 0 .05 ; 1400 1700 0 .05
    0 4 1400 1700 ; 0 4 1400 1700 ];


axesMajors = [1400 1700 0 45; 0 80 0 0.15; ...
    0 45 0 0.15; 1400 1700 0 0.15
    0 4 1400 1700 ; 0 4 1400 1700 ];

[a,IndiciesFig1_X]=(ismember(IndiciesFig1_X_string,ResultLabels));
[a,IndiciesFig1_Y]=(ismember(IndiciesFig1_Y_string,ResultLabels));




IndiciesX = [IndiciesFig1_X];
IndiciesY = [IndiciesFig1_Y];


numcolumns = 2;
numrows = 2;


 for n = 1:numcolumns.*numrows     
        yvalue =  IndiciesY(n);
        xvalue = IndiciesX(n);
        
        ytext=  IndiciesFig1_Y_string{n};
        xtext = IndiciesFig1_X_string{n};
        

        set(gcf, 'Units', 'Inches', 'Position',  [4.3750 2.6528 10.8750 9.7361], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
        subaxis(numrows,numcolumns,n,'Spacing',.03,'Margin',0.02,'Padding',0.01,'PaddingLeft',0.03,'PaddingBottom',.04)
        hold on
        axis square
        
        %axis(axesMajors(n,:))
        
        
        %arg
        % if ismember(n,[1])
        %     yline(11.5,'k','handlevisibility','off');
        %     yline(25.5,'k','handlevisibility','off');
        % end
        %
        % if ismember(n,[2 3 4])
        %     yline(1.5,'k','handlevisibility','off');
        %     yline(1.5,'k','handlevisibility','off');
        % end
        %
        %
        % if ismember(n,[3 5])
        %     xline(11,'k','handlevisibility','off');
        %     xline(12,'k','handlevisibility','off');
        % end
        
        % if n==1
        % % refline(1/1.5,-1250/1.5)
        % % refline(1/1.5,-1300/1.5)
        % refline(1/1.5,-1350/1.5)
        % refline(1/1.5,-1400/1.5)
        % refline(1/1.5,-1450/1.5)
        % refline(1/1.5,-1500/1.5)
        % refline(1/1.5,-1550/1.5)
        % refline(1/1.5,-1600/1.5)
        % refline(1/1.5,-1650/1.5)
        % refline(1/1.5,-1700/1.5)
        % % refline(1/1.9,-1300/1.9)
        % % refline(1/1.1,-1300/1.1)
        %
        %
        % %refline(1/1.5,-1350/1.5)
        % %axis(axesMajors(n,:))
        % end
        
        
 
    % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
        plot(runningSprRate(i),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizesBad{1}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'handlevisibility','on');
            
            
        
        aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
          plot(runningSprRate(i),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}));
            
            
            aaas=aaas+1;
        end
        
        
        
        
        if strcmp(xtext,'FCEXTENT')==1
            %set(gca,'xscale','log')
            %set(gca, 'Xtick',[.01 .1 1 10])
            %axis([0 70 10^-2 10^2 ])
            set(gca, 'Xtick',[0:10:65])
        end
        
        if strcmp(ytext,'BEST FIT')==1
            % set(gca,'yscale','log')
            % set(gca, 'Ytick',[.01 .1 1 10 30])
        end
        
        if strcmp(ytext,'Melting_P_kbar')==1
            
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end
        if strcmp(ytext,'PressureFC')==1
            
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end
        
        %
        % IndiciesFig1_Y_string = {...
        %      'BEST FIT P'  'NRMSD PM'...
        %      'NRMSD PM'  'NRMSD PM'...
        %     };
        %
        % IndiciesFig1_X_string = {'BEST FIT T' 'FC extent'...
        % 'BEST FIT P' 'BEST FIT Tmp' ...
        % };
        
        % xlabel([xtext])
        % ylabel([ytext])
        
        xlabel('Spreading rate')
        ylabel(regexprep(ResultLabels(yvalue),'_',' '))
        
        
        
        box on
        %grid on
  
        set(gca,'ticklength',1.3*[0.0200    0.0500])
        set(gca,'fontsize', 15,'LineWidth',1,'fontname','Times New Roman', 'LineWidth',.7)
        set(gca,'XColor', 'k')
        set(gca,'YColor', 'k')
        %set(gcf,'position',[2.7917 3.4306 9.7361 9.3750])
        % OPTION: uncomment for single (non-subplot plots)
        % legend(TabNames,'location','best')
        % title(FigureTitle)
        % FigureTitle = regexprep(FigureTitle,'\_*','');
        % FigureTitle = regexprep(FigureTitle,'\/','-');

        set(gcf,'name',regexprep(FigureTitle,'\_*',''))
        %uistack(h2,'bottom')
        % uistack(h1,'bottom')
        
        
             %set(gca, 'Ytick',[.01 .1 1 10 100])
        ax = gca;
        ax.XAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        if ax.XLim(1) == 1200
            increment = 10;
        end
       % ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);
        numIncre = (ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1))/increment;
 
        ax.XAxis.MinorTickValues = ax.XAxis.TickValues(1)-numIncre.*increment:increment:ax.XAxis.TickValues(end)+numIncre.*increment;
        
         
        
        %ax.XAxis.MinorTickValues = [.01:.01:.1 .2:.2:1 2:1:10 20:10:100];
        ax.YAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
        ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);
        
        
end   



leg2=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}});
set(leg2,'position',[0.2427 0.8623 0.1954 0.0963])

%%
figure(37)
close
figure(37)
hold on
FigureTitle = 'Spreading Rate Info';
        
ResultLabels = RevPetResultsTable_ResultsOnly.Properties.VariableNames;
% PointNum	Region_Label	Melting_P_kbar	Melting_T_C	apparentT_P	OPALM_RMSD	StabilityField	MgNum_Erupted	MgNum_Primary	MgNum_Olivine	Avg_P_kbar	Stdev_P_kbar...
%     Average_T_C	Stdev_T_C	Average_TP_C	Stdev_TP_C	Avg_MgNum	Stdev_MgNum	Average_percentFC	Stdev_percentFC	FieldPTString	DistanceFromField	FailureReason	...
%     GarSpPlagTransitions	DistanceToNearestBoundary	PressureFC	OPAM_RMSD_Erupted	OPM_RMSD_Erupted	MG_CPX	MG_PLAG	OPA_FC	OP_FC	O_FC	totalFC	...
%     SiO2_Primary	TiO2_Primary	Al2O3_Primary	Cr2O3_Primary	FeO_Primary	MnO_Primary	MgO_Primary	CaO_Primary	Na2O_Primary	K2O_Primary	P2O5_Primary	NiO_Primary	H2O_Prim	total_Prim	...
%     MgNum_Prim	NaKNum_Primary	CaOAl2O3wt_Primary	CaOAl2O3mol_Primary	Na2OFeO_Primary	K2OTiO2_Primary	OneMinusMgNum_Primary ....
%     Qtz_Primary	Plag_Primary	Oliv_Primary	Cpx_Primary	Ox_Primary	Or_Primary	Ap_Primary	He_Primary	Cs_Primary	Rb_Primary	Tl_Primary	K_Primary	Li_Primary	Ba_Primary	Pb_Primary	Sr_Primary	Mn_Primary	Co_Primary	Zn_Primary	Cu_Primary	Ni_Primary	Be_Primary	La_Primary	Ce_Primary	Pr_Primary	Nd_Primary	Sm_Primary	Eu_Primary	Gd_Primary	Tb_Primary	Dy_Primary	Ho_Primary	Y_Primary	Er_Primary	Yb_Primary	Lu_Primary	Sc_Primary	Ga_Primary	Cr_Primary	Th_Primary	U_Primary	Zr_Primary	Hf_Primary	Sn_Primary	Mo_Primary	Ti_Primary	V_Primary	Nb_Primary	Ta_Primary	W_Primary	H2O_Primary	Ra_Primary	ThU_Primary	LuHf_Primary	SmNd_Primary	LuSc_Primary	HfNd_Primary	LaSm_Primary	RbSr_Primary	EuSm_Primary	EuGd_Primary	NdZr_Primary	SmYb_Primary	ZrY_Primary	NbY_Primary	GdYb_Primary	ZrYb_Primary	ZrHf_Primary	NbTa_Primary	BaLa_Primary	BaPb_Primary	UPb_Primary	EuAnom_Primary	KU_Primary


IndiciesFig1_Y_string = {...
    'Melting_P_kbar' 'apparentT_P'...
    'FeO_Primary' 'Na2O_Primary' ...
    };




% axesMajors = [1200 1400 -6 18; 0 65 10^-2 30; ...
%  -6 18 10^-2 30 ; 1200 1350 10^-2 30;...
%  0 18 10^-2 30; 1200 1350 10^-2 30];

% axesMajors = [1200 1400 -6 18; 0 65 10^-2 2; ...
%  -6 18 10^-2 2 ; 1200 1350 10^-2 2];
axesMajors = [1400 1700 0 40; 0 80 0 .05; ...
    0 40 0 .05 ; 1400 1700 0 .05
    0 4 1400 1700 ; 0 4 1400 1700 ];


axesMajors = [1400 1700 0 45; 0 80 0 0.15; ...
    0 45 0 0.15; 1400 1700 0 0.15
    0 4 1400 1700 ; 0 4 1400 1700 ];

[a,IndiciesFig1_X]=(ismember(IndiciesFig1_X_string,ResultLabels));
[a,IndiciesFig1_Y]=(ismember(IndiciesFig1_Y_string,ResultLabels));




IndiciesX = [IndiciesFig1_X];
IndiciesY = [IndiciesFig1_Y];


numcolumns = 2;
numrows = 2;


 for n = 1:numcolumns.*numrows     
        yvalue =  IndiciesY(n);
        xvalue = IndiciesX(n);
        
        ytext=  IndiciesFig1_Y_string{n};
        xtext = IndiciesFig1_X_string{n};
        

        set(gcf, 'Units', 'Inches', 'Position',  [4.3750 2.6528 10.8750 9.7361], 'PaperUnits', 'Inches', 'PaperSize', [8.5, 11])
        subaxis(numrows,numcolumns,n,'Spacing',.03,'Margin',0.02,'Padding',0.01,'PaddingLeft',0.03,'PaddingBottom',.04)
        hold on
        axis square
        
        %axis(axesMajors(n,:))
        
        
        %arg
        % if ismember(n,[1])
        %     yline(11.5,'k','handlevisibility','off');
        %     yline(25.5,'k','handlevisibility','off');
        % end
        %
        % if ismember(n,[2 3 4])
        %     yline(1.5,'k','handlevisibility','off');
        %     yline(1.5,'k','handlevisibility','off');
        % end
        %
        %
        % if ismember(n,[3 5])
        %     xline(11,'k','handlevisibility','off');
        %     xline(12,'k','handlevisibility','off');
        % end
        
        % if n==1
        % % refline(1/1.5,-1250/1.5)
        % % refline(1/1.5,-1300/1.5)
        % refline(1/1.5,-1350/1.5)
        % refline(1/1.5,-1400/1.5)
        % refline(1/1.5,-1450/1.5)
        % refline(1/1.5,-1500/1.5)
        % refline(1/1.5,-1550/1.5)
        % refline(1/1.5,-1600/1.5)
        % refline(1/1.5,-1650/1.5)
        % refline(1/1.5,-1700/1.5)
        % % refline(1/1.9,-1300/1.9)
        % % refline(1/1.1,-1300/1.1)
        %
        %
        % %refline(1/1.5,-1350/1.5)
        % %axis(axesMajors(n,:))
        % end
        
        
 
    % Original Data that RevPet does not find a Valid Solution
    aaas=1;
    for zztemp = 1:size(Unique_BAD_labels_Rows,1)
        Unique_BAD_label_here = Unique_BAD_labels{zztemp};
        i =find(ismember(CombinedLabel, Unique_BAD_label_here));
        p=ismember(i,BAD_ReverseFC);
        i(p==0)=[];
        
        zz = i(1);
        plot(runningSprRate(i),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizesBad{1}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}),'handlevisibility','on');
            
            
        
        aaas=aaas+1;
    end
    
    
        % Original Data with Valid Solutions 
        aaas=1;
        for zz = UniqueLabels_Rows'
            i =find(ismember(CombinedLabel, CombinedLabel(zz)));
            p=ismember(i,highlight_ReverseFC);
            i(p==0)=[];
            
          plot(runningSprRate(i),eval(sprintf('RevPetResultsTable_ResultsOnly.%s(i)',ytext)),...
                runningMarkers{zz},'LineWidth',1,'MarkerSize',eval(runningSizes{zz}), 'Color',eval(runningColors_LINE{zz}),'MarkerFaceColor',eval(runningColors_FILL{zz}));
            
            
            aaas=aaas+1;
        end
        
        
        
        
        if strcmp(xtext,'FCEXTENT')==1
            %set(gca,'xscale','log')
            %set(gca, 'Xtick',[.01 .1 1 10])
            %axis([0 70 10^-2 10^2 ])
            set(gca, 'Xtick',[0:10:65])
        end
        
        if strcmp(ytext,'BEST FIT')==1
            % set(gca,'yscale','log')
            % set(gca, 'Ytick',[.01 .1 1 10 30])
        end
        
        if strcmp(ytext,'Melting_P_kbar')==1
            
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end
        if strcmp(ytext,'PressureFC')==1
            
            set(gca,'YDir','Reverse')
            %set(gca, 'Ytick',[.01 .1 1 10 100])
        end
        
        %
        % IndiciesFig1_Y_string = {...
        %      'BEST FIT P'  'NRMSD PM'...
        %      'NRMSD PM'  'NRMSD PM'...
        %     };
        %
        % IndiciesFig1_X_string = {'BEST FIT T' 'FC extent'...
        % 'BEST FIT P' 'BEST FIT Tmp' ...
        % };
        
        % xlabel([xtext])
        % ylabel([ytext])
        
        xlabel('Spreading rate')
        ylabel(regexprep(ResultLabels(yvalue),'_',' '))
        
        
        
        box on
        %grid on
  
        set(gca,'ticklength',1.3*[0.0200    0.0500])
        set(gca,'fontsize', 15,'LineWidth',1,'fontname','Times New Roman', 'LineWidth',.7)
        set(gca,'XColor', 'k')
        set(gca,'YColor', 'k')
        %set(gcf,'position',[2.7917 3.4306 9.7361 9.3750])
        % OPTION: uncomment for single (non-subplot plots)
        % legend(TabNames,'location','best')
        % title(FigureTitle)
        % FigureTitle = regexprep(FigureTitle,'\_*','');
        % FigureTitle = regexprep(FigureTitle,'\/','-');

        set(gcf,'name',regexprep(FigureTitle,'\_*',''))
        %uistack(h2,'bottom')
        % uistack(h1,'bottom')
        
        
             %set(gca, 'Ytick',[.01 .1 1 10 100])
        ax = gca;
        ax.XAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.XLim(2)- ax.XLim(1),ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1));
        if ax.XLim(1) == 1200
            increment = 10;
        end
       % ax.XAxis.MinorTickValues = ax.XLim(1):increment:ax.XLim(2);
        numIncre = (ax.XAxis.TickValues(2) -  ax.XAxis.TickValues(1))/increment;
 
        ax.XAxis.MinorTickValues = ax.XAxis.TickValues(1)-numIncre.*increment:increment:ax.XAxis.TickValues(end)+numIncre.*increment;
        
         
        
        %ax.XAxis.MinorTickValues = [.01:.01:.1 .2:.2:1 2:1:10 20:10:100];
        ax.YAxis.MinorTick = 'on';
        increment = findBestIncrement( ax.YLim(2)- ax.YLim(1),ax.YAxis.TickValues(2) -  ax.YAxis.TickValues(1));
        ax.YAxis.MinorTickValues = ax.YLim(1):increment:ax.YLim(2);
        
        
end   



leg2=legend({Unique_BAD_labels_leg{:} UniqueLabels_leg{:}});
set(leg2,'position',[0.2427 0.8623 0.1954 0.0963])

%%
figure(30)

plot(runningSprRate./20, runningDepth,'ko','MarkerFaceColor','k')

xlabel('Half-spreading rate (cm/yr)')
ylabel('Axial Depth')
        box on
        %grid on
  
        set(gca,'ticklength',1.3*[0.0200    0.0500])
        set(gca,'fontsize', 15,'LineWidth',1,'fontname','Times New Roman', 'LineWidth',.7)
        set(gca,'XColor', 'k')
        set(gca,'YColor', 'k')
return
%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%cab is a "close all but" function, so tell it the figuers you want to keep (once you have the axes the way you want) 
%and then run this section to save the figures e.g., 
cab 1 25
savefigsPDF(worksheetName2Save,subfolder)